交叉表查詢統計

2021-04-20 21:18:18 字數 679 閱讀 9104

create table  t  (class varchar(2),calldate datetime, callcount int)

insert into t select '1','2005-8-8',40

union all select '1','2005-8-7',6

union all select '2','2005-8-8',77

union all select '3','2005-8-9',33

union all select '3','2005-8-8',9

union all select '3','2005-8-7',21

--動態sql

select * from t

declare @s varchar(8000)

set @s='select calldate '

select @s=@s+',[callcount'+class+']=sum(case when class='''+class+''' then callcount else 0 end)'

from t

group by class

set @s=@s+' from t group by calldate order by calldate desc '

exec(@s)

drop table t

交叉表查詢 LINQ to DataSet

fill the dataset.dataset ds new dataset ds.locale cultureinfo.invariantculture filldataset ds datatable orders ds.tables salesorderheader datatable de...

統計 交叉表 日期 優先 sql

交叉表,根據優先順序取資料,日期處理 create table tb qid int,rid nvarchar 4 tagname nvarchar 10 starttime smalldatetime,endtime smalldatetime,startweekday int,endweekda...

Access交叉表的查詢

轉自 user表 userid username 1 test 2 myname 3 hello type表 typeid typename 1 三年制大專 2 五年制大專 3 中專 user type表 id userid typeid nums 1 1 1 5 2 1 2 3 3 2 1 2 4...