當前位置:首頁 » 編程語言 » sql中數據豎著顯示
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql中數據豎著顯示

發布時間: 2022-11-22 06:36:00

A. sql developer查詢出來的數據默認是橫著顯示,怎樣將查詢的數據豎著顯示例如下圖所示

你問的是 Oracle自己的 sql developer 吧

在查詢結果的表格 的 窗口中,

右鍵 --> 單個記錄視圖

即可。

B. plsql 中查詢時 怎樣讓查詢結果 縱表顯示

plsql的查詢要求列示固定的,類型也是一樣的,所以你的要求可以在外部應用程序實現

C. SQL 怎麼把橫向數據變成豎向數據

隨緣寫法···可能有更精簡的,我這就趕著想趕著寫的 你看看能看懂不,如果覺得對不懂可以聯系我

select
nn.客戶 客戶,
nn.昵稱 昵稱,
nn.補單日期1 補單日期1,
nn.業務員1 業務員1,
nn.補單日期2 補單日期2,
nn.業務員2 業務員2,
nn.補單日期3 補單日期3,
nn.業務員3 業務員3,
nn.補單日期4 補單日期4,
nn.業務員4 業務員4,
nn.業務員1 首選業務員,
nn.業務員2||'-'||nn.業務員3||'-'||nn.業務員4 候選業務員
from (
select tt.a2 客戶,tt.a3 昵稱,wm_concat (case when tt.top=0 then tt.a0 else '' end) 補單日期1,
wm_concat (case when tt.top=0 then tt.a4 else ''end) 業務員1,
wm_concat (case when tt.top=1 then tt.a0 else ''end) 補單日期2,
wm_concat (case when tt.top=1 then tt.a4 else ''end) 業務員2,
wm_concat (case when tt.top=2 then tt.a0 else ''end) 補單日期3,
wm_concat (case when tt.top=2 then tt.a4 else ''end) 業務員3,
wm_concat (case when tt.top=3 then tt.a0 else''end) 補單日期4,
wm_concat (case when tt.top=3 then tt.a4 else ''end) 業務員4
from
(
select zz.* from
(
select a.*,(select count(1) from a a1 where a1.a2=a.a2 and a.a0<a1.a0) top from a ORDER BY A2,A0 DESC
) zz
where
zz.top<4
) tt group by tt.a2,tt.a3
) nn



D. SQL 如何查詢時 橫著的數據 豎著顯示

看你表結構是什麼樣的吧,最徹底的方法是把表結構就改成 姓名,科目,分數。如果表結構是 姓名,數學,語文,英語 不能變,又一定要顯示成那樣,就只好用union拼一下了,比如 select 姓名,'數學' as 科目,數學 as 分數 from 表 union select 姓名,'語文' as 科目,語文 as 分數 from 表 union select 姓名,'英語' as 科目,英語 as 分數 from 表。

E. 求mysql客戶端。用sql語句查詢數據時,能豎形顯示欄位名、值、欄位注釋。

Mysql縱列查詢成橫列展示(橫列增加展示列)

結合case語句就可以實現。

F. plsql查詢語句結果顯示是豎著顯示,怎麼改成橫著顯示

點一下此處即可

G. 如何通過sql將表中豎向數據轉換成橫向數據

行列轉換等經典SQL語句

參考資料:http://blog.csdn.net/kiki113/archive/2009/04/24/4105929.aspx

1.--行列轉換

原表: 姓名 科目 成績
張三 語文 80
張三 數學 90
張三 物理 85
李四 語文 85
李四 物理 82
李四 英語 90
李四 政治 70
王五 英語 90

轉換後的表: 姓名 數學 物理 英語 語文 政治
李四 0 82 90 85 70
王五 0 0 90 0 0
張三 90 85 0 80 0

實例:
create table cj --創建表cj
(
ID Int IDENTITY (1,1) not null, --創建列ID,並且每次新增一條記錄就會加1
Name Varchar(50),
Subject Varchar(50),
Result Int,
primary key (ID) --定義ID為表cj的主鍵
);
--Truncate table cj
--Select * from cj
Insert into cj
Select '張三','語文',80 union all
Select '張三','數學',90 union all
Select '張三','物理',85 union all
Select '李四','語文',85 union all
Select '李四','物理',82 union all
Select '李四','英語',90 union all
Select '李四','政治',70 union all
Select '王五','英語',90
--行列轉換
Declare @sql varchar(8000)
Set @sql = 'Select Name as 姓名'
Select @sql = @sql + ',sum(case Subject when '''+Subject+''' then Result else 0 end) ['+Subject+']'
from (select distinct Subject from cj) as cj --把所有唯一的科目的名稱都列舉出來
Select @sql = @sql+' from cj group by name'
Exec (@sql)

2. 行列轉換--合並
原表: 班級 學號
1 1
1 2
1 3
2 1
2 2
3 1
轉換後的表: 班級 學號
1 1,2,3
2 1,2
3 1

實例:
Create table ClassNo --創建表ClassNo
(
ID Int IDENTITY(1,1) not null, --創建列ID,並且每次新增一條記錄就會加1
Class Varchar(50), --班級列
Number Varchar(50), --學號列
Primary Key(ID) --定義ID為表ClassNo的主鍵
);
--Truncate Table ClassNo
--Select * from ClassNo
Insert Into ClassNo
Select 1,1 Union all
Select 1,2 Union all
Select 1,3 Union all
Select 2,1 Union all
Select 2,2 Union all
Select 3,1

創建一個合並的函數
--Drop Function KFReturn
Create Function KFReturn(@Class Varchar(50))
Returns Varchar(8000)
as
Begin
Declare @str Varchar(8000)
Set @str = ''
Select @str = @str + cast(Number as Varchar(50)) + ',' from ClassNo Where Class = @Class
Set @str = SubString(@str,1,len(@str)-1)
Return(@str)
End

--調用自定義函數得到結果
Select Distinct Class,dbo.KFReturn(Class) From ClassNo

3:列轉行
--Drop Table ColumnToRow
Create table ColumnToRow
(
ID Int IDENTITY(1,1) not null, --創建列ID,並且每次新增一條記錄就會加1
a int,
b int,
c int,
d int,
e int,
f int,
g int,
h int,
Primary Key(ID) --定義ID為表ColumnToRow的主鍵
);
--Truncate Table ColumnToRow
--Select * from ColumnToRow
Insert Into ColumnToRow
Select 15,9,1,0,1,2,4,2 Union all
Select 22,34,44,5,6,7,8,7 Union all
Select 33,44,55,66,77,88,99,12

Declare @sql Varchar(8000)
Set @sql = ''
Select @sql = @sql + rtrim(name) + ' from ColumnToRow union all Select ' from SysColumns Where id = object_id('ColumnToRow')
Set @sql = SubString(@sql,1,len(@sql)-70)
--70的長度就是這個字元串'from ColumnToRow union all Select ID from ColumnToRow union all Select ',因為它會把ID這一列的值也算進去,所以要把它截掉
Exec ('Select ' + @sql + ' from ColumnToRow')

H. SQL裡面如何將豎著的列橫著顯示

一般這樣的情況
如果是我做的話
就預先建立一個表
設置time1
time1
time3……
然後
分別逐次以
no
和日期為
time
分組
;行標題
time
為列標題

值(求和)……對先前建立的表進行追加……
SQL
我不太熟悉
在access

完全可以做的……
還有
如果
你能夠
把你的時間
劃分成不同的時間段
而對應到固定的時間段中的話,完全
直接可以使用
一個交叉查詢就可以了……
但願
這個提示
對你有所幫助……

I. sql server2005 只查詢一個欄位f_mz 怎樣讓它橫排顯示數據而不是豎著顯示呢

試試看這樣呢?

selectdistinctf_mz+''frommzcurtable,pubdatabase_qy..fytablewheref_code3=f_codeanddatebetween'2010-04-2000:00:00'and'2013-08-2000:00:00'forxmlpath('')

J. SQL 如何查詢時 豎著的數據 橫著顯示

你這個是將縱表轉換為橫表,例如如下數據:
'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_name
and a.v_name=c.v_name
and a.v_name='wangming'
and a.v_course='shuxue'
and b.v_course='yuwen'
and c.v_course='yingyu';