java - 数据库查询多表
習慣沉默
習慣沉默 2017-05-18 10:45:06
[MySQL讨论组]

前提 oralce,mybatis
现在有多张表
我现在需要统计每张表里面的信息的数量,也就是count(*)

我现在的方法是写了多个方法
比如 mapper里:
long selectCountA;
long selectCountB;
long selectCountC;

这样的话,我要去数据库里查三次。分别获得3个数据
我想能不能 写一句sql语句 直接获得三个值

求解?

。能给我一个oracle语句的吗, 咋都是mysql。。

習慣沉默
習慣沉默

全部回复(4)
巴扎黑
select "a" name, count(1)
from tableA
union
select "b" name, count(1)
from tableB
union
select "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;
PHPz
select A.countA,B.countB from (select count(*) as countA from t_countA) as A ,(select count(*) as countB from t_countB) as B

这样?

过去多啦不再A梦

Mysql

Oracle
在以上语句后面加 from dual

某草草

Mysql的
select table_rows from information_schema.TABLES where table_schema in ('schema1','schema2','scheman') and table_name in ('tableName1','tableName2','tableNameN')
相信 oralce也有类似的系统表

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号