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. mysql 时间类型 字段(精确到时分秒) 怎么比较?2. PHP类封装的插入数据,总是插入不成功,返回false;3. javascript - vue中怎么使用原生js插件4. javascript - antDesign的table column最后一次加载的时候this是undefined 怎么回事5. javascript - swiperjs 在移动端 又手指滑动 会顿卡 ,怎么解决呢6. pdo 写入到数据库的内容为中文的时候写入乱码7. 网页爬虫 - python+requests 网页重定向求解8. javascript - 小白求解:mac 下如何设置nodejs express的 NODE_NEV 环境变量9. css3动画 - css3 animation初始动画卡顿是怎么回事?10. laravel ORM 一对一 一对多 多对多 原生的MYSQL怎么写?
![android-studio - 一直无法下载android studio的 安卓模拟器求助](http://www.haobala.com/attached/image/news/202310/095450fe73.jpg)