首页 > 代码库 > 根据时间分组

根据时间分组

$sql ="select sum(total),convert(char(10),createtime,120) createtime
from tb
group by convert(char(10),createtime,120)
order by sum(total) desc

";

$sql2 ="select sum(total) 总合, convert(varchar(7),createtime,120) as 月
from orders 
group by convert(varchar(7),createtime,120)";

 

$sql3 = "select sum(total) as 总和 ,convert(char(10),createtime,120) createtime
from tb
where datepart(month,createtime)=datepart(month,getdate())
group by convert(char(10),createtime,120)
";

$sql4 =" select
    convert(datetime, floor(convert(float, createtime))), sum(total)
from
    orders
group by
    floor(convert(float, createtime))
";

/*
上面的四种mssql 各有各的优点,各位可以试一下。
*/

根据时间分组