可能说的不是很清楚,请看例子:
id name mingxi remark
1 小林 111 目晶
1 小林 222 22国
1 小林 333 321加
2 苏青 120 式林止
比如我要挑出明细条数多于等于3的id应该如何做?(上面的表里边,id为1的记录有3条明细,显然就是我要挑出来的,SQL该如何做?)
6 个解决方案
#1
select id from xxxx group by id having count(id)>1
未经测试,可能有误,仅供参考
未经测试,可能有误,仅供参考
#2
非常感谢fj_jiangqi(强盗)!!
再问一句:能不能将具体的明细也挑出来啊?(只要明细数目多于3条,则把这些明细挑出来)
行不?
再问一句:能不能将具体的明细也挑出来啊?(只要明细数目多于3条,则把这些明细挑出来)
行不?
#3
SELECT * FROM Tab1 WHERE ID IN
(SELECT ID FROM Tab1 GROUP BY ID HAVING COUNT(ID) >= 3)
(SELECT ID FROM Tab1 GROUP BY ID HAVING COUNT(ID) >= 3)
#4
SELECT * FROM T1 WHERE ID=
(SELECT ID FROM T1 GROUP BY ID HAVING COUNT(ID) >= 3)
(SELECT ID FROM T1 GROUP BY ID HAVING COUNT(ID) >= 3)
#5
谢谢各位,分不多……
谢谢!
谢谢!
#6
SELECT * FROM 表名 WHERE ID IN ( SELECT ID FROM 表名 GROUP BY ID HAVING count(*) >= 3) order by ID
#1
select id from xxxx group by id having count(id)>1
未经测试,可能有误,仅供参考
未经测试,可能有误,仅供参考
#2
非常感谢fj_jiangqi(强盗)!!
再问一句:能不能将具体的明细也挑出来啊?(只要明细数目多于3条,则把这些明细挑出来)
行不?
再问一句:能不能将具体的明细也挑出来啊?(只要明细数目多于3条,则把这些明细挑出来)
行不?
#3
SELECT * FROM Tab1 WHERE ID IN
(SELECT ID FROM Tab1 GROUP BY ID HAVING COUNT(ID) >= 3)
(SELECT ID FROM Tab1 GROUP BY ID HAVING COUNT(ID) >= 3)
#4
SELECT * FROM T1 WHERE ID=
(SELECT ID FROM T1 GROUP BY ID HAVING COUNT(ID) >= 3)
(SELECT ID FROM T1 GROUP BY ID HAVING COUNT(ID) >= 3)
#5
谢谢各位,分不多……
谢谢!
谢谢!
#6
SELECT * FROM 表名 WHERE ID IN ( SELECT ID FROM 表名 GROUP BY ID HAVING count(*) >= 3) order by ID