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. angular.js - 各位大神們,你們混合開發(fā),web方式中更推薦用什么框架呀? react?vue?angular?謝謝~2. angular.js - angularjs的自定義過濾器如何給文字加顏色?3. angular.js使用$resource服務(wù)把數(shù)據(jù)存入mongodb的問題。4. docker-machine添加一個已有的docker主機(jī)問題5. javascript - IOS微信audio標(biāo)簽不能通過touchend播放6. html - 如何用css令背景圖能夠撐滿本身會滾動的頁面?7. 老師百度網(wǎng)盤分享一下WampServer的包啊,我們下載幾kb要下載一天的.8. javascript - htaccess rewrite 的問題9. 自己安裝了apache2.2,但是重啟apache后出錯了,求解!謝謝!10. html5 - vuex 為什么需要action,我發(fā)現(xiàn)進(jìn)行異步操作回調(diào)中直接操作mutation也沒有報錯
