把倆條MySQL語句合併成一條,把倆條MySQL語句合併成一條

時間 2021-10-14 22:25:42

1樓:司馬刀劍

最笨的方式就是把這麼多條查詢結果當成表,然後select全部,雖然笛卡爾積,但是每個查詢都只有一條記錄。

select * from(select count(t1.fxm)as a1 from kj_kjhdrymxb t1 where t1.fdw = 'a部' )a,(select count(t2.

fjszw)as a2 from kj_kjhdrymxb t2 where t2.fjszw = '專案人員' and t2.fdw = 'a部')b,(select count(t3.

fjszw)as a3 from kj_kjhdrymxb t3 where (t3.fjszw = '服務人員'or t3.fjszw = '管理人員') and t3.

fdw = 'a部')c,(select count(t31.fxb)as a4 from kj_kjhdrymxb t31 where t31.fxb = '女' and t31.

fdw = 'a部')d(select count(t4.fzc)as a5 from kj_kjhdrymxb t4 where (t4.fzc = '高階職稱'or t4.

fzc = '中級職稱')and t4.fdw = 'a部')d,(select count(t5.fxm)as a6 from kj_kjhdrymxb t5 where t5.

fdw = 'a部')e(select count(t6.fxl)as a7 from kj_kjhdrymxb t6 where t6.fxl = '博士'and t6.

fdw = 'a部')f(select count(t7.fxl)as a8 from kj_kjhdrymxb t7 where t7.fxl = '碩士' and t7.

fdw = 'a部')g(select count(t8.fxl)as a9 from kj_kjhdrymxb t8 where t8.fxl = '本科'and t8.

fdw = 'a部')h

2樓:匿名使用者

兩張表有關聯關係嗎,兩張表沒有關係的話用union all  或者 union 將兩個查詢結果拼成一個結果集,在查詢那個結果集;(union all 和 union 請參考連線:http://www.

w3school.com.cn/sql/sql_union.

asp)

eg:select alarmhour,twicecount from (

select date_format(a.atime,'%h') as alarmhour,

count(*) as twicecount

from z_alarm a

where a.s_est=1 and a.ifdel=0 and a.atime like '2019-02-18%'

group by date_format(a.atime,'%h')

union all

select date_format(b.atime,'%h') as alarmhour,

count(*) as twicecount

from z_alarm_false b where b.atime like '2019-02-18%'

group by date_format(b.atime,'%h')

) aa

mysql 寫一條查詢語句,合併一個欄位下兩個內容

3樓:匿名使用者

select name from 表名

union

select name from 表名

我認為牛頓三定律可以合併成一條定律

你說的是正確的。但是,並不是句子越少越簡潔。有時,多個簡單句更簡潔,如很多法律條文。的確,一定律是二定律的特例。要知道,我們任何規律的掌握,都是從特例開始的!牛頓三定律反映了人類認知的一個過程。起源,是從慣性定律的思考開始的。我們回過頭來看,三定律當然都簡單如廢話。但是,還是要保留思考的痕跡,因為三...

分析一條語句

一句話,0.5就是為了實現四捨五入,因為強制轉換double為int是,小數部分全部舍掉了。於是 0.5使其四捨五入,減小誤差 v i 100難道不是整數嗎?v i 是double型,v i 100就不會是整型的,除非你在前面加上強制轉換 int for i 0 i s str.push back ...

PLC一條程式設計語句的疑問

1t0 和dt0的區別 是16位和32位的區別嗎?2這個語句的意識是x1接通 然後設定後面的引數 t0 k1 k1 d352 k1 用於以後的程式?3這2條句子裡有很多相同的引數,我不知為什麼要這樣設定?解疑 1,t0和dto是寫入所指引數到特殊模組,與之類似的還有from和dfrom,是由指定的特...