當前位置:首頁 » 編程語言 » sql同一個表的不同列匯總查詢
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql同一個表的不同列匯總查詢

發布時間: 2022-05-05 08:22:21

⑴ 在sql語句實現查詢一張表中的同一個屬性的不同欄位的所有數據

oracle的話有個wmsys.wm_concat函數可以實現
select dosname,wmsys.wm_concat(doswork) from work group by dosname;

⑵ 在SQL表中如何一起查詢兩個列(同一個表中)

select * from tab1
union all
select * from tab2

前提2個表數據相同
或者左右外內鏈接查詢 都一樣
lefe join
right join
full join

⑶ sql從同一表裡查詢多條不同條件的數據

試試:
select
a_id,
a_title,
a_name
from
A
where
a_id=10
union
all
select
*
from
(
select
top
1
a_id,
a_title,
a_name
from
A
where
a_id<10
order
by
a_id
desc)
union
all
select
top
1
a_id,
a_title,
a_name
from
A
where
a_id>10

⑷ SQL 把不同列的號碼匯總代碼怎麼寫

這個不是匯總,就是欄位合並
只是你的SQL是什麼資料庫(有幾十個常用資料庫,它們都支持SQL語言的,但字串合並方法不同的),若是SQLServer(注意,SQL與SQLserver是不同的概念)
可用
select 員工姓名,手機號碼+'*'+電話號碼 可聯系號碼 from 你的表

⑸ sql語句,查出同一表中同一列不同類型的數據同時查出。

select * from tab where C='33' or C='34';
or是或者,其一匹配就會顯示,所以33和34都會顯示
and是而且,也就是兩個條件必須同時滿足

⑹ 同一張表的不同列怎麼用sql將查詢出來的值和在一起

兩種方法。
一。
select * from A

union
select * from B
二。
select

(case when M then else 0 end 1 ),
(case when N then else 0 end 1 )
from A,B

⑺ sql語句如何查詢一個表中某一列的不同數據

select * from 表名稱 where "工裝(欄位名)=工裝名,輔料(欄位名)=輔料,站位(欄位名)=站位"

⑻ sql里查詢一個欄位里的記錄的多個類的匯總(幾個欄位按不同分類的匯總)

--技術要點:行轉列
--以下提供SQL SERVER語句

--創建測試環境
create table tab
(
machine int,
sernum varchar(10),
area varchar(2),
PF varchar(1)
)
--製造數據
insert into tab select 462,'16205R3E','AT','P'
insert into tab select 462,'16203H0N','AT','F'
insert into tab select 316,'1620A7WP','AT','S'
insert into tab select 316,'16206CCC','AT','S'

--1. 靜態行轉列(所謂靜態,是指的PF列只有P,F,S這三個值,或者值是固定的某幾個值)
select machine,
max(case pf when 'P' then num else 0 end) as P,
max(case pf when 'F' then num else 0 end) as F,
max(case pf when 'S' then num else 0 end) as S
from
(select machine,pf,count(1) as num from tab group by machine,pf
)tb
group by machine

/* 結果集
machine P F S
----------- ----------- ----------- -----------
316 0 0 2
462 1 1 0

(2 row(s) affected)
*/

--2. 動態行轉列(相對於靜態的概念)
declare @sql varchar(8000)
set @sql = 'select machine as ' + 'machine'
select @sql = @sql + ' , max(case pf when ''' + pf + ''' then num else 0 end) [' + pf + ']'
from (select distinct pf from tab) as a
set @sql = @sql + ' from (select machine,pf,count(1) as num from tab group by machine,pf
)tb group by machine'
exec(@sql)

/* 結果集
machine F P S
----------- ----------- ----------- -----------
316 0 0 2
462 1 1 0

(2 row(s) affected)
*/

--刪除環境
drop table tab

⑼ 如何將SQL中同一個表中的兩列記錄合並查詢

使用union。
select column1 from table union select column2 from table

⑽ 在SQL裡面怎麼把同一個表中的列相同的匯總 另外一列平均一下

你好!
select
sum(a),avg(b)
from

a是匯總欄位
b是平均欄位
如有疑問,請追問。