一个sql合并行问题
现在有一张这样的表
MC DATA DATE
一号 1 2009-11-12
一号 2 2009-11-13
一号 3 2009-11-14
一号 5 2009-12-01
二号 1 2009-11-12
二号 3 2009-11-13
二号 4 2009-11-14
二号 5 2009-12-01
要求查询09年11月分所有数据的总和,查询下来是下面这样
MC DATA
一号 6
二号 8
忘了写谢谢了。谢谢啊
select mc,sum(DATA) as DATA
where date between '2009-11-1' and '2009-11-30'
group by mc
SQL code:
select mc,sum(data) as data
from tb
where convert(varchar(7),date,120) = '2009-11'
group by mc
SQL code:
if not object_id('tb') is null
drop table tb
Go
Create table tb([MC] nvarchar(2),[DATA] int,[DATE] Datetime)
Insert tb
select N'一号',1,'2009-11-12' union all
select N'一号',2,'2009-11-13' union all
select N'一号',3,'2009-11-14' union all
selec
相关问答:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jas ......
可能因为工作的原因 接触数据库这块比较少,之前都是做程序这块,数据库这块都有专门的人来做 分工都很明细 所以对数据库这一块完全不了解。前段时间 去面试了几家公司 几乎都是在数据库这块挂掉的 连个简单的SQ ......
现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle)
现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......
第一句:
select ht.gfdm,gfdm.gfmc,gfdm.lb ,sum(jh.htdj*jh.htsl)as je
from ht left join gfdm on ht.gfdm=gfdm.gfdm
join jh on ht.htbh=jh.hth
and ht.htbh not like'del%' and ht. ......