sql 列轉行
將一條查詢結果,本開始橫向的一條記錄,想讓他顯示為一列,此處查詢了130項因子資料,sql語句看著嚇人,只看一兩行就ok
轉換結果
sql語句:
select b.c1 as climate_value from climate_index b where tm='195101' union all
select b.c2 as climate_value from climate_index b where tm='195101' union all
select b.c3 as climate_value from climate_index b where tm='195101' union all
select b.c4 as climate_value from climate_index b where tm='195101' union all
select b.c5 as climate_value from climate_index b where tm='195101' union all
select b.c6 as climate_value from climate_index b where tm='195101' union all
......
......
select b.c125 as climate_value from climate_index b where tm='195101' union all
select b.c126 as climate_value from climate_index b where tm='195101' union all
select b.c127 as climate_value from climate_index b where tm='195101' union all
select b.c128 as climate_value from climate_index b where tm='195101' union all
select b.c129 as climate_value from climate_index b where tm='195101' union all
select b.c130 as climate_value from climate_index b where tm='195101' ;
SQL 列轉行,即多行合併成一條
需求 按照分組,將多條記錄內容合併成一條,效果如下 資料庫示例 create table t2 nid bigint null,district nvarchar 255 null,town nvarchar 255 null insert into t2 values 1,淮上區 曹老集鎮 ins...
sql 取最新一條記錄
1.選出某個條件最新的一條記錄 選出最新狀態下的每乙個單號對應的子單資料 select distinct a.receiving code,a.product barcode,a.rd putaway qty from odoo ykd oversea shipping information a ...
SQL語句隨機抽取一條記錄
我們經常想在乙個資料表中隨機地選取出資料來,比如隨機生成考試試卷等。利用 sql server 的 newid 方法就可以很輕鬆地達到這個目的。newid 方法返回乙個 guid,如 ee95a489 b721 4e8a 8171 3ca8cb6ad9e4 在 select 表的時候,再增加一列為 ...