如何寫SQL語句按周統(tǒng)計和按季度統(tǒng)計?
--SQLserver2005語法統(tǒng)計按周,月,季,年。--按日--select sum(price),day([date]) from table_name where year([date]) ='2006' group by day([date])--按周quarterselect sum(price),datename(week,price_time) from ble_name whereyear(price_time) = '2008' group by datename(week,price_time)--按月select sum(price),month(price_time) from ble_name where year(price_time)= '2008' group by month(price_time)--按季select sum(price),datename(quarter,price_time) from ble_name whereyear(price_time) = '2008' group by datename(quarter,price_time)--按年select sum(price),year(price_time) from ble_name whereyear(price_time) >= '2008' group by year(price_time)