select SaleID,GoodsID from Table
group by SaleID,GoodsID
例如:
select f1,f2,...,fn
from table
group by f1,f2,...,fn
having count(1)>1 查出存在相同的f1,f2,..,fn
想查找出记录则
select t1.* from table t1
扩展资料:
更新:update table1 set field1=value1 where 范围
查找:select * from table1 where field1 like ’%value1%’ (所有包含‘value1’这个模式的字符串)
排序:select * from table1 order by field1,field2 [desc]
求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from table1
参考资料来源:百度百科-sql语句
select 人名,商品名 from 表名 group by 人名,商品名 having count(*)>=2
按人分组,统计数量,大于2的就查询出来 。
select username from usertb u where exists (
select o.userid,o.productid, count(*) from order o where u.userid=o.userid group by o.userid,o.productid having count(*)>1)
用户表: usertb(userid,username,……)
订单表:order(orderid,userid,productid,……)
group by …… having
比如表table中有 人名Name,产品名products
select Name from table group by name,products having count(*)>2