您好,欢迎来到[编程问答]网站首页   源码下载   电子书籍   软件下载   专题
当前位置:首页 >> 编程问答 >> Web开发 >> (jsp)sql语句逻辑

(jsp)sql语句逻辑

来源:网络整理     时间:2016/5/31 11:24:01     关键词:sql语句

关于网友提出的“(jsp)sql语句逻辑”问题疑问,本网通过在网上对“(jsp)sql语句逻辑”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题:(jsp)sql语句逻辑
描述:

(jsp)sql语句逻辑
这样的数据库表结构 T_CATALOG_ID=1664对应T_CATALOG_STATETIME_STATE=1,2,4,5这样是一个流程走完存的数据,怎么样检索出T_CATALOG_STATETIME_STATE只有1,2这条数据的所有T_CATALOG_ID,即流程只走到2,后面4是待处理状态,还没有到5,即4,5还没有记录的数据


解决方案1:

取t_catalog_statetime_state的最小值与最大值,如果同时满足有1及2,则查询出来
select * from tablename 
where id in (
        select id from (select min(state) minState max(state) maxState,id from tablename   group by id) t
        where t.minState =1 and t.maxState in(1,2)
 )

解决方案2:

引用 17 楼 wanghengwhwh 的回复:
Quote: 引用 16 楼 yqt8926 的回复:

l

是要在已经走完1234里找34的ID吗
select * from tablename where id in (select id from (select COUNT(state) a,id from tablename where state=1 or state=2 or state=4 or state=5  group by id
having COUNT(state)>4) temp) and (state=4 or state=5) 解决方案3:

把有4,5的取出来,然后再取补集。
select distinct T_CATALOG_ID from TABLENAME t where t.T_CATALOG_ID is not in (select distinct T_CATALOG_ID from TABLENAME t1 where t1.t_catalog_statetime_state=4 or t1.t_catalog_statetime_state=5);

解决方案4:

SELECT T_CATALOG_ID FROM TABLENAME GROUP BY T_CATALOG_ID HAVING COUNT(T_CATALOG_ID) = 2 AND T_CATALOG_STATETIME_STATE < 4

解决方案5:

select  count(1)  as num from table t1  where t1.t_catalog_statetime_state = 2 and not exists (
      select 1 from table t2  where t2.t_catalog_statetime_state > t1.t_catalog_statetime_state);

解决方案6:

不选4,5 那你 T_CATALOG_STATETIME_STATE!=4 or T_CATALOG_STATETIME_STATE!=5啊
你把数据列出来  要的结果列出来 我仔细看看


以上介绍了“(jsp)sql语句逻辑”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/1432634.html

相关图片

相关文章