java - 數據庫查詢多表
問題描述
前提 oralce,mybatis現在有多張表 我現在需要統計每張表里面的信息的數量,也就是count(*)
我現在的方法是寫了多個方法 比如 mapper里:long selectCountA;long selectCountB;long selectCountC;
這樣的話,我要去數據庫里查三次。分別獲得3個數據我想能不能 寫一句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也有類似的系統表
相關文章:
1. bootstrp是col-md-12列的,只有col-md-10有內容,可以讓沒有內容的不占據位置嗎;2. java - 如何用圖畫的方式有效地表示多線程?3. thinkPHP5中獲取數據庫數據后默認選中下拉框的值,傳遞到后臺消失不見。有圖有代碼,希望有人幫忙4. python - Fiddler+Android模擬器抓取app,json數據被加密了,如何解析?5. 常量在外面不加引號會報錯。6. sublime text3安裝package control失敗7. python 3.4 error: Microsoft Visual C++ 10.0 is required8. 百度地圖 - Android app中準備接入地圖sdk,百度VS高德哪個好一點?9. wordpress里,這樣的目錄列表是屬于小工具還是啥?10. 我的怎么不顯示啊,話說有沒有QQ群什么的
