原创转载请注明出处:http://agilestyle.iteye.com/blog/2392433
有一张数据表DDR
问题:查询出T2重复出现1次以上的记录
SQL Reference
select * from ddr
where t2 in
(
select t2 from ddr
group by t2
having count(t2) > 1
);
数据库2张表,一张Customer,字段id,name;一张Orders,字段id,cid(Customer的ID外键),revenue,问题:查询出每个Customer的revenue总和
SQL Reference
select sum(revenue), c.name
from orders o LEFT JOIN customer c on o.cid = c.id
GROUP BY cid;