我有这个疑问
select 'firstname' as attr_name, count(id) as count_id, count(id) - count(firstname) as count_missing, count(firstname) as count_total from person
union
select 'lastname' as attr_name, count(id) as count_id, count(id) - count(lastname) as count_missing, count(lastname) as count_total from person
假设第一个查询运行了大约5秒,第二个查询也运行了5秒,如果我运行整个联合查询,那么它将花费大约10秒。所以它基本上运行单个查询并合并结果。
有没有一种方法可以达到同样的效果,但所需的时间会减少?
我想不出除此之外的任何可能的解决方案。
1条答案
按热度按时间pu3pd22g1#
这应该只在整个表中进行一次扫描: