午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    跪求sql server2012行轉列方案
    來源:易賢網(wǎng) 閱讀:918 次 日期:2014-12-22 15:30:26
    溫馨提示:易賢網(wǎng)小編為您整理了“跪求sql server2012行轉列方案”,方便廣大網(wǎng)友查閱!

    下面為表創(chuàng)建代碼:

    create table [dbo].[productauditrecord]([parid] [nchar](12)

    not null,[moid] [nchar](12)

    not null,[lotsn] [nvarchar](50)

    not null,[cosmeticinspection] [nchar](12)

    not null,[functionaltest] [nchar](12)

    not null,[unumber] [nchar](50)

    null,[leadwire] [nchar](50)

    null,[resourceid] [nchar](12)

    not null,[userid] [nchar](12)

    not null,[remark] [nvarchar](100)

    null,[creatdate] [datetime] not null,[productid] [nchar](12)

    not null,[nextid] [int] not null, constraint [pk_productauditrecord] primary key clustered

    ([parid] asc)with

    (pad_index = off, statistics_norecompute = off,

    ignore_dup_key = off, allow_row_locks = on,

    allow_page_locks = on) on [primary])

    on [primary]goalter table [dbo].[productauditrecord] add

    constraint [df_productauditrecord_parid] default

    (substring(convert([char](36),

    newid(),(0)),(1),(12)))

    for [parid]goalter table [dbo].

    [productauditrecord] add constraint

    [df_productauditrecord_nextid] default

    ((0))

    for [nextid]go

    下面為自己測試數(shù)據(jù)得到的結果:上面為原始數(shù)據(jù),下面為轉換后的數(shù)據(jù):轉換代碼

    測試表代碼:create table [dbo].[test](

    [月份] [varchar](4) null,

    [工資] [int] null,

    [福利] [int] null,

    [獎金] [int] null

    ) on [primary]

    1:月份 工資 福利 獎金

    1月 100 200 300

    2月 110 210 310

    3月 120 220 320

    4月 130 230 330

    2:考核月份 1月 2月 3月 4月

    福利 200 210 220 230

    工資 100 110 120 130

    獎金 300 310 320 330

    select * from

    (

    select 考核月份,月份,金額 from

    (select 月份, 工資, 福利, 獎金 from test) p

    unpivot

    (金額 for 考核月份 in (工資, 福利, 獎金))as unpvt

    ) t

    pivot

    (max(金額) for 月份 in ([1月],[2月],[3月],[4月]))as pt

    更多信息請查看IT技術專欄

    更多信息請查看數(shù)據(jù)庫
    易賢網(wǎng)手機網(wǎng)站地址:跪求sql server2012行轉列方案

    2025國考·省考課程試聽報名

    • 報班類型
    • 姓名
    • 手機號
    • 驗證碼
    關于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權所有:易賢網(wǎng)