SQL如何將查詢結果橫排顯示,sql中怎麼讓結果集橫向顯示?

2022-03-15 16:36:33 字數 1709 閱讀 8091

1樓:匿名使用者

這只是一個合併語句就搞定了。

select floor,group_contact(roomid,"##") as roomid from tablename group by floor;

用二個##分隔如得到的結果是 1000##1001如果直接用group_contact(roomid)則是以,號分隔 如1000,1001

輸出時用字串工具處理下就可以了。

2樓:天極宇智波

這是行轉列 可使用如下sql語句即可實現:

select name,

sum(case course when '語文' then score end ) as '語文',

sum(case course when '數學' then score end ) as '數學',

sum(case course when '英語' then score end ) as '英語'

from grade group by name

可參照下面方式:

sql中怎麼讓結果集橫向顯示?

sql查詢結果中想橫向顯示

sql 如何查詢時 豎著的資料 橫著顯示??

3樓:匿名使用者

select name,

sum(case when subject='數學' then score else 0 end) as '數學',

sum(case when subject='語文' then score else 0 end) as '語文',

sum(case when subject='英語' then score else 0 end) as '英語'

from table group by name最好有學號區分,如果重名就不好弄了

4樓:

你這個是將縱錶轉換為橫表,例如如下資料:

'wangming', 'shuxue', 100'wangming', 'yuwen', 90'wangming', 'yingyu', 140可以使用如下語句處理:

select a.v_name,a.v_score shuxue,b.

v_score yuwen,c.v_score yingyu from temp_1 a,temp_1 b,temp_1 c

where a.v_name=b.v_nameand a.v_name=c.v_nameand a.v_name='wangming'

and a.v_course='shuxue'

and b.v_course='yuwen'

and c.v_course='yingyu';

sql怎麼樣合併兩個查詢結果 橫向顯示出來?

5樓:匿名使用者

select a.d_roomid,a.d_type,b.d_roomid,b.d_personname from

roomprice a

left join register b on b.d_exchange='否' and b.d_state='未結帳'

and a.d_roomid=b.d_roomid

sql語句如何將表進行關聯查詢,sql語句如何將三個表進行關聯查詢?

select distinct a.caseno caseno,a.daterecived,a.buildid,a.contractno,max b.dateofrmi dateofrmi,c.venue,c.district from a left join b on a.caseno b.cas...

SQL如何顯示查詢結果的前100條

sqlserver支援top關鍵字,返回前100條資料。selecttop100 from table 返回前100行資料 mysql支援limit,一個引數 select from table limit 100 返回前100行記錄 oracle需要使用rownum。select from tab...

sql查詢結果如何自動換行,SQL查詢分析器能不能自動換行

可以在sql語句中加換行符chr 10 實現,比如欄位a長度為150,sql可以這麼寫 select substr t.a,0,100 char 10 substr t.a,101,len t.a from table t 或者你也可以將內容複製出來,放入一個自動換行的記事本,儲存之後就是換行後的結...