java - 數(shù)據(jù)庫查詢多表
問題描述
前提 oralce,mybatis現(xiàn)在有多張表 我現(xiàn)在需要統(tǒng)計(jì)每張表里面的信息的數(shù)量,也就是count(*)
我現(xiàn)在的方法是寫了多個(gè)方法 比如 mapper里:long selectCountA;long selectCountB;long selectCountC;
這樣的話,我要去數(shù)據(jù)庫里查三次。分別獲得3個(gè)數(shù)據(jù)我想能不能 寫一句sql語句 直接獲得三個(gè)值
求解?
。能給我一個(gè)oracle語句的嗎, 咋都是mysql。。
問題解答
回答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在以上語句后面加 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. atom開始輸入!然后按tab只有空格出現(xiàn)沒有html格式出現(xiàn)2. javascript - js setTimeout在雙重for循環(huán)中如何使用?3. javascript - vue-cli npm run build編譯報(bào)錯(cuò)4. mysql - 這種分級一對多,且分級不平衡的模型該怎么設(shè)計(jì)表?5. mac里的docker如何命令行開啟呢?6. javascript - 有適合開發(fā)手機(jī)端Html5網(wǎng)頁小游戲的前端框架嗎?7. java - 創(chuàng)建maven項(xiàng)目失敗了 求解決方法8. python - pip install出現(xiàn)下面圖中的報(bào)錯(cuò) 什么原因?9. java - 線上應(yīng)用,如果數(shù)據(jù)庫操作失敗的話應(yīng)該如何處理?10. php - MySQL數(shù)據(jù)庫設(shè)計(jì),獲取點(diǎn)贊的人數(shù)
