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

在多列上分布任意行

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

問題描述

我有一張材料表.我需要填寫該表中的數(shù)據(jù)輸入表.

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

問題是數(shù)據(jù)輸入表單被分成多列,每列包含許多材料,如圖所示.如何編寫 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.

推薦答案

在客戶端執(zhí)行此操作可能最簡單,而不是在數(shù)據(jù)庫中執(zhí)行此操作,但如果您真的想執(zhí)行此操作,我會假設最簡單的方法將行分成 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() 與行數(shù)除以 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模板網(wǎng)!

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

相關文檔推薦

Modify Existing decimal places info(修改現(xiàn)有小數(shù)位信息)
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)
主站蜘蛛池模板: 日韩精品一区二区三区在线观看 | 黄色在线免费播放 | 日本成人一区二区 | 中文精品一区二区 | 涩色视频在线观看 | 日本欧美国产在线 | 欧美精品成人 | 中文字幕国产视频 | 国产精品福利在线 | 久久激情视频 | 成人久久久 | 亚洲成人一区二区三区 | 自拍偷拍小视频 | 武道仙尊动漫在线观看 | 成人自拍视频网站 | 国产精品爱久久久久久久 | 天堂一区 | 在线不卡视频 | 精品国产一区二区三区久久 | 亚洲国产中文字幕 | 岛国毛片| 国产精品区一区二区三区 | 蜜桃毛片 | 三级成人片 | 欧美群妇大交群中文字幕 | 99国产视频 | 久久久久久久久久久国产 | 欧美一区视频 | 免费久久网站 | 亚洲精品久久久久久久久久久 | 99这里只有精品视频 | 午夜激情影院 | 欧美xxxx色视频在线观看免费 | 精品视频在线观看 | 一区二区视频免费观看 | 国产一二区视频 | 欧洲精品码一区二区三区免费看 | 欧美一区二区三区在线观看 | 请别相信他免费喜剧电影在线观看 | 北条麻妃视频在线观看 | 国产分类视频 |