我的查询有问题。
错误是:{“无效的列名'TotalRecords'。”}
我在这个表中有一个名为upload_news的表有很多记录,我想按国家/地区检索数据,在不同的国家/地区有超过20条记录。
select count(Distinct country) AS TotalRecords, country from upload_news where TotalRecords > 20";
答案 0 :(得分:2)
您需要使用Group By和Having:
select count(Distinct country) AS TotalRecords, country from upload_news
group by country
having count(Distinct country) > 20
答案 1 :(得分:1)
试试这个
"SELECT *
FROM
(
select count(Distinct country) AS TotalRecords, country from upload_news
group by country
) T
where TotalRecords > 20";
因为 TotalRecords 别名列,您无法直接访问它。