Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
SELECT COUNT(*) FROM ( SELECT 1 FROM ... UNION SELECT 1 FROM ... UNION SELECT 1 FROM ... ) as tmp_table
尽管结果集包括多行,但COUNT(*)总是返回 1... 为什么?
COUNT(*)
UNION SELECT自动对结果进行分组,这意味着您不会看到重复的行。你需要的是UNION ALL SELECT...,那么你的结果将不会被分组,你会看到重复的行。
UNION SELECT
UNION ALL SELECT...
重复行的意思,因为你总是选择1,所以它按1分组。