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 如何實現動態的行列轉置SQL
- Spark實現行列轉換pivot和unpivotSpark
- 報表如何實現行列互換效果?
- 使用vue實現行列轉換的一種方法。Vue
- 在報表中錄入資料時如何實現行列轉換
- 實現二維陣列的行列互換陣列
- mysql行列轉換詳解MySql
- Restcloud ETl實踐之資料行列轉換RESTCloud
- 記錄一個行列轉換
- Oracle行列轉換及pivot子句的用法Oracle
- web 展現資料時如何實現行列互換Web
- 例項詳解構建數倉中的行列轉換
- sql隱式轉換SQL
- WPF 型別轉換器的實現型別
- jenkins:實現Jenkinsfile與Json的轉換JenkinsJSON
- vue+vant 實現 rem的轉換VueREM
- 使用Python 實現 PDF 到 HTML 的轉換PythonHTML
- [顏色進位制轉換]js實現rgb和hex的相互轉換JS
- Spark SQL中的RDD與DataFrame轉換SparkSQL
- python實現中文和unicode轉換PythonUnicode
- python實現字串轉換整數Python字串
- Java實現emf轉jpg png 圖片轉換Java
- Lambda 轉換 SQL ORM 工具 SqlRepoExSQLORM
- Python+numpy實現矩陣的行列擴充套件Python矩陣套件
- 日期與字串的互相轉換SQL語句字串SQL
- 【型別轉換】使用c#實現簡易的型別轉換(Emit,Expression,反射)型別C#MITExpress反射
- 用Java實現samza轉換成flinkJava
- 如何實現隱式型別轉換型別
- flask實現python方法轉換服務FlaskPython
- Oracle SQL_ID轉換成SQL_HASH_VALUEOracleSQL
- 將表結構轉換成實體欄位
- 【轉】【SQL】 實現左單一匹配SQL
- JPG轉PDF如何實現?圖片批次轉換PDF的快捷方法
- C++實現任意進位制的相互轉換C++
- 【SQL】Oracle查詢轉換之 OR用法SQLOracle
- HGDB的分割槽表實現SQL Server的分割槽檢視SQLServer
- 音樂格式轉換:java程式碼實現Java
- C++實現進位制轉換工具C++
- Python實現批次將ppt轉換為pdfPython