sql
作者:互联网
select * from Appointment where yyid in ('2021051100000012','2021051900000018','2021052100000021') 用以下代替: select * FROM Appointment a JOIN ( select '2021051100000012' yyid union select '2021051900000018' UNION SELECT '2021052100000021' ) b on a.yyid=b.yyid
select a.* from Appointment a where a.yyid in(select yyid from OrderPayment where ReceivableAmount=3000 ) 用下面的语句替换: select a.* from Appointment a where 1=1 and exists(select 1 from OrderPayment where yyid=a.yyid and ReceivableAmount=3000 )
SELECT * FROM phonebill --取出每月通话费最高和最低的两个地区。 SELECT TOP 2 * FROM phonebill WHERE net_type = 'G' GROUP BY bill_month ORDER BY area_code DESC SELECT BILL_MONTH, AREA_CODE, SUM ( LOCAL_FARE ) LOCAL_FARE, FIRST_VALUE ( AREA_CODE ) OVER ( PARTITION BY BILL_MONTH ORDER BY SUM ( LOCAL_FARE ) DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) FIRSTVAL, LAST_VALUE ( AREA_CODE ) OVER ( PARTITION BY BILL_MONTH ORDER BY SUM ( LOCAL_FARE ) DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) LASTVAL FROM phonebill GROUP BY BILL_MONTH, AREA_CODE ORDER BY BILL_MONTH SELECT bill_month, area_code, SUM ( local_fare ) local_fare, first_value ( area_code ) OVER ( partition BY bill_month ORDER BY SUM ( local_fare ) DESC ROWS BETWEEN unbounded preceding AND unbounded following ) firstval, last_value ( area_code ) OVER ( partition BY bill_month ORDER BY SUM ( local_fare ) DESC ROWS BETWEEN unbounded preceding AND unbounded following ) lastval FROM phonebill GROUP BY bill_month, area_code ORDER BY bill_month SELECT bill_month, area_code, SUM ( local_fare ) local_fare FROM phonebill a GROUP BY bill_month, area_code ORDER BY bill_month SUM ( loc_fare )View Code
标签:yyid,SUM,bill,month,sql,ORDER,select 来源: https://www.cnblogs.com/dyxinfo/p/16546593.html