sqlcount多表
发布时间: 2023-03-12 20:12:47
⑴ SQL如何统计多表总记录数
你是指5张表的总记录还是相关的记录?
SELECT SUN(C) FROM (
SEELCT COUNT(*) C FROM TABLE1
UNION ALL
SEELCT COUNT(*) C FROM TABLE2
UNION ALL
SEELCT COUNT(*) C FROM TABLE3
UNION ALL
SEELCT COUNT(*) C FROM TABLE4
UNION ALL
SEELCT COUNT(*) C FROM TABLE5
);
或者:
SELECT COUNT(*) FROM TABLE1 A
INNER JOIN TABLE2 B ON A.ID=B.ID
INNER JOIN TABLE3 C ON C.ID=B.ID
INNER JOIN TABLE4 D ON D.ID=C.ID
INNER JOIN TABLE5 E ON E.ID=D.ID
热点内容