我用过这个查询
SELECT COUNT(CASE WHEN C <= 1 THEN 1 END) AS nooffamiliesHavingcount1,
COUNT(CASE WHEN C BETWEEN 2 AND 4 THEN 1 END) AS nooffamiliesHavingcountbetween2And4,
COUNT(CASE WHEN C > 4 THEN 1 END) AS nooffamiliesHavingcountgreaterthan3
FROM ( SELECT COUNT(*) AS C
FROM user where user_id = (select user_id from location where location_id in(select location_id from country where state_name='STATE'))
GROUP BY House_No
) t
这里子查询返回大约 10000 条记录。用户表有 10,00,000 条记录。它花费了太多时间。然后它说的错误是服务器消失了。我正在使用mysql。
我从谷歌搜索。但我没有运气。
我需要对我的表进行哪些更改。如何通过提高查询性能成功执行此查询。请建议我。提前致谢....