日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

t-sql中pivot用法(行列轉換)

系統 2321 0

從另一張表找的3974行是張三,8319行是李四,3051行是王五;

從stu_score查id,stu_id兩列,聚合求出 得出張三,李四,王五在stu_score中的記錄條數?

select ? [ 3974 ] ? as ?張三,? [ 8319 ] ? as ?李四,? [ 3051 ] ? as ?王五
from ?
(
select ?id,stu_id? from ?stu_score)? as ?s
pivot
(
????
count (id)
????
for ?stu_id? in ?( [ 3974 ] , [ 8319 ] , [ 3051 ] )
)
as ?pvt

?

? T-SQL Pivot Syntax

SELECT

??[non-pivoted column], -- optional

??[additional non-pivoted columns], -- optional

??[first pivoted column],

??[additional pivoted columns]

FROM (

??SELECT query producing sql da ta for pivot

??-- select pivot columns as dimensions and

??-- value columns as measures from sql tables

) AS TableAlias

PIVOT

(

??<aggregation function>(column for aggregation or measure column) -- MIN,MAX,SUM,etc

??FOR [<column name containing values for pivot table columns>]

??IN (

????[first pivoted column], ..., [last pivoted column]

??)

) AS PivotTableAlias

?

select ?exam_name? as ?考試名稱,? [ 407 ] ? as ?一班,? [ 408 ] ? as ?二班,? [ 409 ] ? as ?三班,? [ 415 ] ? as ?九班
from
(
select ?dept_id,?exam_name,? [ language ] ?
from ?stu_score,stu_studentinfo?
where ?stu_score.stu_id? = ?stu_studentinfo.id)? as ?t
pivot
(
????
avg ( [ language ] )
????
for ?dept_id? in ?( [ 407 ] , [ 408 ] , [ 409 ] , [ 415 ] )
)
as ?pvt

結果如下:

考試名稱 一班 二班 三班 九班
考試一 89.26 88.33 90.36 85.25
考試二 82.26 87.98 80.36 85.25
期末 81.26 83.33 80.36 78.25

t-sql中pivot用法(行列轉換)


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。。?/p>

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 东源县| 丹江口市| 清涧县| 丽水市| 宾阳县| 隆安县| 邹平县| 二连浩特市| 互助| 蒙城县| 夏津县| 汝州市| 大新县| 禹城市| 新野县| 山东省| 兴仁县| 甘孜县| 海阳市| 临朐县| 聂荣县| 阳信县| 遵义县| 太和县| 中西区| 商城县| 贞丰县| 会泽县| 高碑店市| 常德市| 温宿县| 晋江市| 营口市| 钦州市| 韩城市| 宜良县| 安义县| 潜山县| 阳新县| 马鞍山市| 威海市|