久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在多列上分布任意行

Distribute arbitrary rows on multiple columns(在多列上分布任意行)
本文介紹了在多列上分布任意行的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一張材料表.我需要填寫該表中的數據輸入表.

I have a table of materials. I need to fill a data entry form from that table.

問題是數據輸入表單被分成多列,每列包含許多材料,如圖所示.如何編寫 tsql select 查詢,將第一組材料名稱放入一列,將第二組材料名稱放入第二列,依此類推.

The problem is that the data entry form is divided into multiple columns each one containing a a number of materials as in the picture. How to write a tsql select query to obtain the first bunch of material names into a column, the second bunch into a second column and so on.

推薦答案

在客戶端執行此操作可能最簡單,而不是在數據庫中執行此操作,但如果您真的想執行此操作,我會假設最簡單的方法將行分成 3 組是使用 row_number() 模 3 并使用它構建單獨的列.這將使行的順序略有不同:

It might be easiest to do this in the client side, and not in the database, but if you really want to do this, I would assume the simplest way to distribute rows into 3 groups is to use row_number() with modulo 3 and build separate columns using that. That will order the rows slightly differently:

A    B    C
D    E    F
G    H

如果您需要按其他順序排列,則需要將 row_number() 與行數除以 3.這樣您就可以按順序排列了

If you need to have them in the other order, then you need to divide the row_number() with the number of rows divided by 3. That will you get them in the order

A    D    G
B    E    H
C    F

示例:

select
  max(case when GRP = 0 then VALUE end),
  max(case when GRP = 1 then VALUE end),
  max(case when GRP = 2 then VALUE end)
from
(
    select 
      (row_number() over (order by VALUE)-1) % 3 as GRP, 
      (row_number() over (order by VALUE)-1) / 3 as ROW, 
      VALUE
    from table1
)X
group by ROW

SQL Fiddle

示例如何以另一種方式劃分行:

Example how to divide the rows the other way:

declare @NOLINES int
select @NOLINES = ceiling(count(*) / 3.0) from table1

select
  max(case when GRP = 0 then VALUE end),
  max(case when GRP = 1 then VALUE end),
  max(case when GRP = 2 then VALUE end)
from
(
    select 
      (row_number() over (order by VALUE)-1) / @NOLINES as GRP, 
      (row_number() over (order by VALUE)-1) % @NOLINES as ROW, 
      VALUE
    from table1
)X
group by ROW

這篇關于在多列上分布任意行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Modify Existing decimal places info(修改現有小數位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關名稱“CONVERT)
T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
remove duplicates from comma or pipeline operator string(從逗號或管道運算符字符串中刪除重復項)
Change an iterative query to a relational set-based query(將迭代查詢更改為基于關系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 欧美日韩在线视频观看 | www.午夜| 九一九色国产 | 日本乱轮视频 | 国产精品99久久久久久久久 | 欧美激情一区二区 | 久久久久一区 | 欧美日韩在线一区二区 | 啪啪免费网站 | 午夜影院黄 | 黄色一级小说 | 黄视频在线播放 | 四虎影视大全 | 婷婷色综合 | 国产一区二区三区免费视频 | 中文字幕免费观看 | 一级黄色网 | 国产一级免费 | 日韩精品少妇 | 欧美视频一区二区三区 | 欧美日韩一二区 | 午夜拍拍 | 99热在线免费观看 | 亚洲激情欧美 | 国产精品婷婷 | 免费观看成人 | 精品免费国产一区二区三区四区 | 欧美黄色网 | 亚洲黄色精品 | 97精品国产露脸对白 | 九九天堂| 午夜在线免费观看 | 中文字幕av久久爽一区 | 日本免费不卡视频 | 欧美成人精品一区二区 | 国产精品久久一区二区三区 | 国产精品一区视频 | 日本一区二区不卡视频 | 国产三级久久 | 欧美黄色一区二区 | 国产三级视频 |