SQL语句之GroupBy

表如下:完成每个企业、每年的超标比例
 
SQL:

select EnterpriseCode as UID,
   year(MonitorTime) as 'Year' ,
   EnterpriseName as 名称,
   ( SUM(OverStatus)*100.0/(count(*)) ) as AMOUNT
from Ent_EnterpriseOverWeightStatusDay
where CHARINDEX(CAST((year(MonitorTime)) as nvarchar),'2008,2009')>0
group by EnterpriseCode,YEAR(MonitorTime),EnterpriseName

 

结果:

 
posted @ 2013-10-09 17:23  昱众不同  阅读(635)  评论(0)    收藏  举报