sql 實現表的行列轉換
下面的兩個儲存過程是公司網站統計編輯釋出哪些型別的文章用到的,實現了資料表的行列轉換
create proc EditorWork_AccountByTopicname1--編輯工作按文章內容型別統計各欄目的文章數
@starttime varchar(50),--查詢開始時間
@endtime varchar(50)--查詢結束時間
as
declare @sql varchar(8000)
set @sql='select content_topic_name '
select @sql=@sql+',['+ctname+']=sum(case ctname when '''+ctname+''' then counts else 0 end)' from (select count(a.id) as counts,ctname=isnull(case a.InfoContentType when 1 then '入門' when 2 then '技術' when 3 then '市場' when 4 then '理論研究' when 5 then '產品分析' when 6 then '應用實施' when 7 then '典型案例' end,'ZERO'),b.content_topic_name from articleinfo a,content_topic b where b.content_topic_id=a.contenttopic and a.contenttopic<>0 and a.addtime<@endtime and a.addtime>@starttime group by InfoContentType,content_topic_name) aa
group by ctname
print @sql
exec(@sql+' from (select count(a.id) as counts,ctname=isnull(case a.InfoContentType when 1 then ''入門'' when 2 then ''技術'' when 3 then ''市場'' when 4 then ''理論研究'' when 5 then ''產品分析'' when 6 then ''應用實施'' when 7 then ''典型案例'' end,''ZERO''),b.content_topic_name from articleinfo a,content_topic b where b.content_topic_id=a.contenttopic and a.contenttopic<>0 and a.addtime<'''+@endtime+''' and a.addtime>'''+@starttime+''' group by InfoContentType,content_topic_name ) aa group by content_topic_name')
GO
相關文章
- SQL Server 實現行列(縱橫表)轉換SQLServer
- 在SQL Server 2005中實現表的行列轉換SQLServer
- 行列轉換sqlSQL
- 用abap實現內表的行列轉換-原始碼2 (轉)原始碼
- Oracle--SQL行列轉換實戰OracleSQL
- sql server 行列轉換SQLServer
- sql行列轉置的實現方法SQL
- sql語句實現表的行列倒置SQL
- 行列轉換 交叉表 (轉)
- sql server行列轉換案例SQLServer
- 【SQL 學習】行列轉換SQL
- 【SQL】行列轉換方法示例SQL
- pivot、unpivot實現oracle行列轉換Oracle
- 報表如何實現行列互換效果?
- SQL 如何實現動態的行列轉置SQL
- 試驗Oracle中實現行列轉換的方法(轉)Oracle
- Spark實現行列轉換pivot和unpivotSpark
- 使用vue實現行列轉換的一種方法。Vue
- 在Word中實現表格的行列互換 (轉)
- WORD及EXCEL行列轉換實現方法收藏(轉)Excel
- 在報表中錄入資料時如何實現行列轉換
- SQL Server中行列轉換 Pivot UnPivotSQLServer
- 用ORACLE分析函式實現行列轉換Oracle函式
- 行列轉換
- wmsys.wm_concat 實現行列轉換問題
- Kettle行列轉換
- 偽行列轉換!
- SQL Server 2005之PIVOT/UNPIVOT行列轉換(轉)SQLServer
- 複雜的行列轉換
- 幾個行列轉換的實用小例子
- 實現二維陣列的行列互換陣列
- 警示:通過 wmsys.wm_concat 實現行列轉換
- 通用的行列轉換的方法
- 【SQL 分析函式】wm_concat 行列轉換SQL函式
- Oracle-行列轉換Oracle
- MySQL行列轉換拼接MySql
- 行列轉換之大全~~~
- oracle和mysql的行列轉換OracleMySql