要求结果是什么,表中有无唯一标识的字段,假设有
select * from tt a where exists(select 1 from tt where a.f1=f1 and a.f2=f2 and a.id<>id)
select * from tt a where exists(select 1 from tt where a.f1=f1 and a.f2=f2 and a.id<>id)
调试欢乐多
字段1 字段2 字段3 字段4
1 a b c d
2 a c b b
3 a b c c
4 a c c c
5 a b b b
这是5条数据我需要的是经过查询,可以返回数据,第一次返回 1,3,5,因为他们的字段1和字段2是一样的。
第二次返回2,4就类似这个表格是订单行项目,需要整理整个表格,将字段1和字段2相同的数据查出来。再由程序处理成订单合并不知道描述清楚了没,是整理这个表格,生成两个表格的意思。把行项目和头分开
order by f1,f2
order by 字段1,字段2
字段1 字段2 相同是他们的共性
SELECT t.type,t.status,COUNT(*) FROM test_order t GROUP BY t.type , t.status这样就知道有哪几种单据头。type,status相同的单据就查出来了,得到一个list
然后循环list查询数据库,就得到了行。我的描述导致大家对我的需求不是很了解。