我有这样的疑问:
SELECT DISTINCT type, (SELECT count(*) FROM ads WHERE ad_type = description_table.type)
as count FROM description_table;
执行大约需要5分钟。这可能是什么问题?
编辑:将表名从'desc'更改为'description_table'以避免复杂化。
答案 0 :(得分:0)
您需要将表格description_table与广告表相关联。试试这个:
SELECT DISTINCT type, (SELECT count(ads.type) FROM ads join description_table on ads.type = description_table.type)
as count FROM `description_table`;
而不是计算*,尝试计算某些列,如id或类型
修改强>
根据您的评论,您可以尝试此查询:
SELECT a.type, count(d.type) as count
FROM description_table d left join ads a on d.type = a.type
group by d.type;