sql 查询

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhongwenit/article/details/80036562

子查询,金额最大的月份里的详细记录

select * from synpay_consume where substr(INSERT_TIME,0,6)=
 (select month from(
 select COUNT(*) as count,sum(AMOUNT) as sumamt,substr(INSERT_TIME,0,6) as month 
from synpay_consume 
group by substr(INSERT_TIME,0,6)  
order by sumamt desc)
where rownum<2)

删除重复记录

DELETE from user where id in (
SELECT * from 
(SELECT id FROM user 
where sno in( select sno from user group by sno HAVING count(sno)>1) 
and id not in (select min(id) from user group by sno HAVING count(sno)>1)) as t1)

猜你喜欢

转载自blog.csdn.net/zhongwenit/article/details/80036562