日期:2014-05-18 浏览次数:20600 次
select sj,kch,count(1) as zrs from tb group by sj,kch
------解决方案--------------------
if object_id('tb') is not null drop table tb go create table tb ( xh varchar(10), xm varchar(10), sj varchar(10), kch varchar(10) ) go insert into tb select '001','张三','2011-12-01','201' union all select '002','李四','2011-12-01','201' union all select '003','王五','2011-12-03','201' union all select '004','王六','2011-12-01','202' union all select '005','正西','2011-12-02','201' union all select '006','宗八','2011-12-01','201' go select sj,kch,zrs=count(*) from tb group by sj,kch order by sj go /* sj kch zrs ---------- ---------- ----------- 2011-12-01 201 3 2011-12-01 202 1 2011-12-02 201 1 2011-12-03 201 1 (4 行受影响) */