易截截图软件、单文件、免安装、纯绿色、仅160KB

求一句SQL查询语句 - MS-SQL Server / 疑难问题

表结构
ID ArticlesID AddTime
1 1 2010-5-1
2 1 2010-5-2
3 3 2010-5-2
4 2 2010-5-2
5 1 2010-5-2
6 2 2010-5-3
7 1 2010-5-3
8 2 2010-5-3
9 1 2010-5-3

我想知道 2010.5 这个月 ArticlesID 等于 1 的统计情况 效果如下

ArticlesID 日期 统计数
1 2010-5-1 1
1 2010-5-2 2
1 2010-5-3 2


SQL语句怎么写? 在线等!!!
SQL code:
selct ArticlesID,AddTime,统计数=count(1) from tb where ArticlesID=1
group by AddTime

试试

SQL code:
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([ID] int,[ArticlesID] int,[AddTime] datetime)
insert [tb]
select 1,1,'2010-5-1' union all
select 2,1,'2010-5-2' union all
select 3,3,'2010-5-2' union all
select 4,2,'2010-5-2' union all
select 5,1,'2010-5-2' union all
select 6,2,'2010-5-3' union all
select 7,1,'2010-5-3' union all
select 8,2,'2010-5-3' union all
select 9,1,'2010-5-3'

--------------------------------查询开始------------------------------

select [ArticlesID],[AddTime],count(*


相关问答:

sqlserver错误 - MS-SQL Server / 疑难问题

sqlserver2005 建立的数据库,与手持pda传输数据,最近突然出现无法传递数据的问题,pda端提示的错误时outofmemoryexception,但是pda上面的容量没有问题,
sqlserver的日子上的错误如下:
日期 2010-1-25 14:45: ......

求一SQL - MS-SQL Server / 基础类

tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......

SQL server分解XML - MS-SQL Server / 应用实例

下面是XML初始文件内容
XML code:
<upd:Update xmlns:lar="http://schemas.microsoft.com/msus/2002/12/LogicalApplicabilityRules" xmlns:cmd="http://schemas.microsoft.com/msus/2002/12/Up ......

sql 问题 - MS-SQL Server / 基础类

需求如下:
学院 academy(aid,aname)
班级 class(cid,cname,aid)
学生 stu(sid,sname,aid,cid)
住宿区 region(rid,rname)
宿舍楼 build(bid,rid,bnote) bnote是‘男’/‘女’
宿舍 dorm(did,rid,bid,bedn ......

SQL不明白 - MS-SQL Server / 应用实例

查询学生平均成绩及其名次 
  SELECT 1+(SELECT COUNT( distinct 平均成绩) 
  from (SELECT S#,AVG(score) AS 平均成绩 
  from SC&n ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号