java - 數(shù)據(jù)庫查詢多表
問題描述
前提 oralce,mybatis現(xiàn)在有多張表 我現(xiàn)在需要統(tǒng)計每張表里面的信息的數(shù)量,也就是count(*)
我現(xiàn)在的方法是寫了多個方法 比如 mapper里:long selectCountA;long selectCountB;long selectCountC;
這樣的話,我要去數(shù)據(jù)庫里查三次。分別獲得3個數(shù)據(jù)我想能不能 寫一句sql語句 直接獲得三個值
求解?
。能給我一個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. 服務(wù)器端 - 采用nginx做web服務(wù)器,C++開發(fā)應(yīng)用程序 出現(xiàn)拒絕連接請求?2. 關(guān)于docker下的nginx壓力測試3. 為什么我ping不通我的docker容器呢???4. javascript - vue 移動端的input 數(shù)字輸入優(yōu)化5. javascript - 有什么兼容性比較好的辦法來判斷瀏覽器窗口的類型?6. java - 自己制作一個視頻播放器,遇到問題,用的是內(nèi)置surfaceview類,具體看代碼!7. javascript - nidejs環(huán)境設(shè)置操作一直出現(xiàn)這種問題怎么解決?8. python - pandas按照列A和列B分組,將列C求平均數(shù),怎樣才能生成一個列A,B,C的dataframe9. javascript - Angular controlller控制域和原生js的關(guān)系10. angular.js - Ionic 集成crosswalk后生成的apk在android4.4.2上安裝失敗???
