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
熱點內容