java - database query multiple tables
習慣沉默
習慣沉默 2017-05-18 10:45:06
0
4
635

Prerequisite oralce, mybatis
Now there are multiple tables
I now need to count the amount of information in each table, that is, count(*)

My current method is to write multiple methods
For example, in mapper:
long selectCountA;
long selectCountB;
long selectCountC;

In this case, I have to check it three times in the database. Obtain 3 pieces of data respectively
I wonder if I can write a sql statement to directly obtain three values

Solution?

. Can you give me an oracle statement? It's all mysql. .

習慣沉默
習慣沉默

reply all(4)
巴扎黑
select "a" name, count(1)
from tableA
union
select "b" name, count(1)
from tableB
union
select "C" name, count(1)
from tableC

Use multi-column writing method

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;
PHPzhong
select A.countA,B.countB from (select count(*) as countA from t_countA) as A ,(select count(*) as countB from t_countB) as B

Like this?

过去多啦不再A梦

Mysql

Oracle
Add from dual

after the above statement
某草草

Mysql
select table_rows from information_schema.TABLES where table_schema in ('schema1','schema2','scheman') and table_name in ('tableName1','tableName2','tableNameN')
I believe oralce also has a similar system table

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!