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

SQL - 如何根據唯一值組合行

SQL - How to combine rows based on unique values(SQL - 如何根據唯一值組合行)
本文介紹了SQL - 如何根據唯一值組合行的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

下表是從另一個包含 ID、Name、Organ 和 Age 列的表中創建的.器官列中的值是指定器官和狀況的代碼.

The table below was created from another table with columns ID,Name,Organ,and Age. The values found in the Organ column were codes which designated both organ and condition.

使用 CASE 我做了一個這樣的表格:

Using CASE I made a table like this:

--------------------------------------------------------
ID      NAME        Heart   Brain   Lungs   Kidneys AGE
1318    Joe Smith   NULL    NULL    NULL    NULL    50
1318    Joe Smith   NULL    NULL    NULL    NULL    50
1318    Joe Smith   NULL    NULL    NULL    Below   50
1318    Joe Smith   NULL    NULL    NULL    Below   50
1318    Joe Smith   NULL    NULL    Above   NULL    50
1318    Joe Smith   NULL    NULL    Above   NULL    50
1318    Joe Smith   Average NULL    NULL    NULL    50
1318    Joe Smith   Average NULL    NULL    NULL    50
--------------------------------------------------------

我想查詢這個表并得到以下結果:

I would like to query this table and get the following result:

--------------------------------------------------------
1318    Joe Smith   Average NULL    Above   Below   50   
--------------------------------------------------------

換句話說,我想根據每個記錄的唯一值創建一個記錄列.

In other words I would like to create one record based on the unique values from each column.

推薦答案

假設每個器官可以只有一個值或 null,如示例數據所示,max 聚合函數應該可以解決問題:

Assuming each organ can either have just one value or a null, as shown in the sample data, the max aggregate function should do the trick:

SELECT   id, name, 
         MAX(heart), MAX(brain), MAX(lungs), MAX(kidneys), 
         age
FROM     my_table
GORUP BY id, name, age

這篇關于SQL - 如何根據唯一值組合行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應該使用什么 SQL Server 數據類型來存儲字節 [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm Does not return all data(Typeorm 不返回所有數據)
Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
How to convert #39;2016-07-01 01:12:22 PM#39; to #39;2016-07-01 13:12:22#39; hour format?(如何將“2016-07-01 01:12:22 PM轉換為“2016-07-01 13:12:22小時格式?)
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應該返回“1?什么時候不能投射為日期?)
主站蜘蛛池模板: 精品国产乱码久久久久久蜜臀 | 亚洲欧洲日韩 | 久久99深爱久久99精品 | 欧美精品一区二区三区在线播放 | 欧美视频免费 | 狠狠艹| 国产精品毛片无码 | 久久久久久免费看 | 日本欧美视频 | 欧美精品日韩精品 | 国产欧美在线播放 | 成人在线a | 神马影院一区二区三区 | 天天天天天操 | 色影视 | 欧美日韩精品影院 | 天天操天天射综合 | 一区二区免费视频 | 福利国产 | 免费在线观看一区二区三区 | 久久精品国产精品青草 | 日韩欧美国产不卡 | 一级片在线视频 | 午夜在线视频一区二区三区 | 在线欧美日韩 | 国产三级 | 亚洲黄色一区二区三区 | 日日摸天天添天天添破 | 欧美亚洲综合久久 | 天堂视频免费 | 在线视频亚洲 | 超黄视频网站 | 国产h视频 | 亚洲高清一区二区三区 | 中文字幕在线剧情 | 久国产精品 | 中文字幕 在线观看 | 国产亚洲精品精品国产亚洲综合 | 久久久日韩精品一区二区三区 | 国产在线观看一区 | 91在线视频免费观看 |