日期:2014-05-18  浏览次数:20389 次

简单的一条求和sql语句,求解,谢谢。
我有一张表:
category brand Plan_Date M_Sales
----------- ----------- ----------------------- -----------
1292 1294 2011-05-01 00:00:00.000 6452.0000
1292 1294 2011-06-01 00:00:00.000 8526.8000
1292 1294 2011-07-01 00:00:00.000 10890.4000
1292 1294 2011-08-01 00:00:00.000 13542.8000
1292 1294 2011-09-01 00:00:00.000 16484.0000
1292 1294 2011-10-01 00:00:00.000 19714.0000
1292 1296 2011-05-01 00:00:00.000 3328.2000
1292 1296 2011-06-01 00:00:00.000 4380.8000
1292 1296 2011-07-01 00:00:00.000 5577.8000
1292 1296 2011-08-01 00:00:00.000 6919.2000
1292 1296 2011-09-01 00:00:00.000 8405.0000
1292 1296 2011-10-01 00:00:00.000 10035.2000

现在想把六月和七月的M_Sales加总,根据category 和 brand

SQL语句如何写

------解决方案--------------------
SQL code
select category, brand,
sum(M_Sales) as M_Sales
from t1
where Plan_Date  between '2001-06-01' and '2001-07-01'
group by category ,brand

------解决方案--------------------
SQL code
select category,brand,sum(M_Sales)
from tb where month(Plan_Date) in(6,7) group by category,brand

------解决方案--------------------
SQL code
select category,brand,sum(M_Sales)M
from tb
where convert(varchar(7),Plan_date,120) between '2011-06' and '2011-07'
group by category,brand

------解决方案--------------------
SQL code
select
 category, brand,
 sum(M_Sales) as M_Sales
from
 t1
where
 convert(varchar(10),Plan_Date,120)  >= '2001-06-01' and convert(varchar(10),Plan_Date,120)<='2001-07-01'
group by
 category ,brand