有一个表的DATE如下 OBK_NUM OBK_NUM_SPEC OBK_COUNT OBK_FLG_RB ・・・
1 P0000001 1 1 0 ・・・
2 P0000001 1 2 1 ・・・
3 P0000001 1 3 0 ・・・
4 P0000002 1 1 0 ・・・
5 P0000002 1 2 1 ・・・
条件是
1。 OBK_NUM, OBK_NUM_SPEC
2。 OBK_FLG_RB为 0 和 1 的 求出其一条,
当OBK_FLG_RB只为 0 或 1的DETE 舍去。
从上面的DATE 要求出的结果为
OBK_NUM OBK_NUM_SPEC OBK_COUNT OBK_FLG_RB ・・・
1 P0000001 1 1 0 ・・・
4 P0000002 1 1 0 ・・・
或者为
OBK_NUM OBK_NUM_SPEC OBK_COUNT OBK_FLG_RB ・・・
2 P0000001 1 2 1 ・・・
5 P0000002 1 2 1 ・・・这样的SQL怎么写?
解决方案 »
- button问题
- hibernate 获取sequnce的问题,高手请进
- jsp调用java中的方法
- 用asp写word (接分啦)
- <a>标签后的herf写项目中jsp文件地址
- jfreechart<img>标签后接参数 ClientAbortException:java.net.SocketException: Connection reset by peer: socket write error
- 整数问题
- 有关两个IF选择条件的问题
- 求b/s模式的邮件系统 ,在jsp版洒了100分,在这儿继续100分
- jsp有数据库操作的事务处理功能吗?
- 今天面试没有回答好的问题,散分!
- hibernate中如何保存timestamp字段
方案1.取0或1的
select * from table t1 where t1.OBK_FLG_RB = 0 and
exists(select t2.OBK_FLG_RB from table t2 where t2.OBK_NUM = t1.OBK_NUM
and t2.OBK_FLG_RB = 1)方案2:sum group 可用临时表
select OBK_NUM ,count(OBK_NUM) c
from table t1
where c =2
group by OBK_NUM 可以连这个表,作为嵌套表 也可以 先把数据插入临时表 在查 flg = 1 或 0 的
select * from obk t1
where obk_flg_rb=0
and exists
(select 1 from obk
where obk_num=t1.obk_num and obk_flg_rb=1)
group by obk_num;