首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

简单的一条求和sql语句,求解,多谢

2012-01-12 
简单的一条求和sql语句,求解,谢谢。我有一张表:categorybrandPlan_DateM_Sales----------- ----------- ---

简单的一条求和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_Salesfrom t1where 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)Mfrom tbwhere 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_Salesfrom t1where convert(varchar(10),Plan_Date,120)  >= '2001-06-01' and convert(varchar(10),Plan_Date,120)<='2001-07-01'group by category ,brand 

热点排行