Mysql SQL:尝试输出属于满足条件的类别的所有名称时出错
我有以下两个表格: 商店: 信息: 我正在尝试编写一个查询,输出属于所有国家/地区均为日本的类别的所有名称(例如,健康和体育类别中的所有商店均位于日本)。例如,输出将是:Mysql SQL:尝试输出属于满足条件的类别的所有名称时出错,mysql,sql,count,Mysql,Sql,Count,我有以下两个表格: 商店: 信息: 我正在尝试编写一个查询,输出属于所有国家/地区均为日本的类别的所有名称(例如,健康和体育类别中的所有商店均位于日本)。例如,输出将是: Name | Country | Category Pharmacy Japan Health Nature Shop Japan Health Medical 100 Japan Health Sports
Name | Country | Category
Pharmacy Japan Health
Nature Shop Japan Health
Medical 100 Japan Health
Sports Life Japan Sport
Athletics Japan Sport
我有以下代码:
select t1.Code, t1.Country, x.Category
from Shop t1
inner join (select t2.Category, t3.Country
from Info t2, Shop t3
group by t2.Category
having max(t3.Country) = min(t3.Country)
and max(t3.Country) = 'Japan') x
on x.Name = t1.Name;
但是,当我执行查询时,会出现以下错误:
错误:列“t3.country”必须出现在GROUP BY子句中,或在聚合函数中使用
第3行:内部连接(选择t2.类别,t3.国家
我不知道为什么会出现此错误,以及如何修复此错误。非常感谢您提供的任何见解。我不确定您为什么使用子查询,但可以通过使用联接获得所需的结果
select shop.Country,shop.Name,info.Category from shop LEFT JOIN info on shop.name = INFO.name where shop.country ='Japan' and info.Category in ('Health','Sport')
select t1.Code, t1.Country, x.Category
from Shop t1
inner join (select t2.Category, t3.Country
from Info t2, Shop t3
group by t2.Category
having max(t3.Country) = min(t3.Country)
and max(t3.Country) = 'Japan') x
on x.Name = t1.Name;
select shop.Country,shop.Name,info.Category from shop LEFT JOIN info on shop.name = INFO.name where shop.country ='Japan' and info.Category in ('Health','Sport')