国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 數(shù)據(jù)庫(kù) > SQL Server > 正文

SQL Server數(shù)據(jù)庫(kù)動(dòng)態(tài)交叉表的參考示例

2024-08-31 00:52:34
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
SQL Server數(shù)據(jù)庫(kù)動(dòng)態(tài)交叉表的參考示例:

--建立測(cè)試環(huán)境set nocount oncreate table test(model varchar(20),date int ,qty int)insert into test select 'a','8','10'insert into test select 'a','10','50'insert into test select 'b','8','100'insert into test select 'b','9','200'insert into test select 'b','10','100'insert into test select 'c','10','200'insert into test select 'd','10','300'insert into test select 'e','11','250'insert into test select 'e','12','100'insert into test select 'f','12','150'go--測(cè)試declare @sql varchar(8000)set @sql='select model,'select @sql=@sql+'sum(case when date='''+cast(date as varchar(10))+''' then qty else 0 end)['+cast(date as varchar(10))+'],'from (select distinct top 100 percent  date from test order by date)aset @sql =left(@sql,len(@sql)-1)+' from test group by model'exec(@sql)--刪除測(cè)試環(huán)境drop table test set nocount off/**//*model                8           9           10          11          12-------------------- ----------- ----------- ----------- ----------- -----------a                    10          0           50          0           0b                    100         200         100         0           0c                    0           0           200         0           0d                    0           0           300         0           0e                    0           0           0           250         100f                    0           0           0           0           150*/

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 大英县| 中江县| 连州市| 开鲁县| 太康县| 汕尾市| 雷州市| 神木县| 曲阜市| 手游| 新蔡县| 彭山县| 延川县| 天全县| 榆社县| 阿克陶县| 策勒县| 望谟县| 徐州市| 娱乐| 含山县| 天水市| 溆浦县| 定日县| 峨边| 吕梁市| 江源县| 繁峙县| 渭南市| 咸丰县| 东平县| 镇宁| 上饶市| 白山市| 通辽市| 光泽县| 沽源县| 阜宁县| 洞头县| 绩溪县| 历史|