java - 數(shù)據(jù)庫(kù)查詢多表
問(wèn)題描述
前提 oralce,mybatis現(xiàn)在有多張表 我現(xiàn)在需要統(tǒng)計(jì)每張表里面的信息的數(shù)量,也就是count(*)
我現(xiàn)在的方法是寫了多個(gè)方法 比如 mapper里:long selectCountA;long selectCountB;long selectCountC;
這樣的話,我要去數(shù)據(jù)庫(kù)里查三次。分別獲得3個(gè)數(shù)據(jù)我想能不能 寫一句sql語(yǔ)句 直接獲得三個(gè)值
求解?
。能給我一個(gè)oracle語(yǔ)句的嗎, 咋都是mysql。。
問(wèn)題解答
回答1:select 'a' name, count(1)from tableAunionselect 'b' name, count(1)from tableBunionselect 'C' name, count(1)from tableC
采用多列的寫法
with temp_a as (select count(*) num from talbeA),temp_b as (select count(*) num from tableB),temp_c as (select count(*) num from tableC)select temp_a.num, temp_b.num, temp_c.num from dual;回答2:
select A.countA,B.countB from (select count(*) as countA from t_countA) as A ,(select count(*) as countB from t_countB) as B
這樣?
回答3:Mysql
Oracle在以上語(yǔ)句后面加 from dual
回答4:Mysql的select table_rows from information_schema.TABLES where table_schema in (’schema1’,’schema2’,’scheman’) and table_name in (’tableName1’,’tableName2’,’tableNameN’)相信 oralce也有類似的系統(tǒng)表
相關(guān)文章:
1. docker - 各位電腦上有多少個(gè)容器啊?容器一多,自己都搞混了,咋辦呢?2. java - spring boot 如何打包成asp.net core 那種獨(dú)立應(yīng)用?3. java - 在用戶不登錄的情況下,用戶如何添加保存到購(gòu)物車?4. datetime - Python如何獲取當(dāng)前時(shí)間5. javascript - nginx反向代理靜態(tài)資源403錯(cuò)誤?6. docker網(wǎng)絡(luò)端口映射,沒(méi)有方便點(diǎn)的操作方法么?7. 安全性測(cè)試 - nodejs中如何防m(xù)ySQL注入8. javascript - 關(guān)于apply()與call()的問(wèn)題9. docker start -a dockername 老是卡住,什么情況?10. python - 調(diào)用api輸出頁(yè)面,會(huì)有標(biāo)簽出現(xiàn),請(qǐng)問(wèn)如何清掉?
