我有以下两个表:
店:
Name | Country
Pharmacy Japan
Green Vine Italy
Red Palace Morocco
La Pizza Italy
Nature Shop Japan
Medical 100 Japan
Sports Life Japan
Athletics Japan
信息:
Name | Category | Price
Pharmacy Health Cheap
Green Vine Dining Medium
Red Palace Dining Expensive
La Pizza Dining Cheap
Nature Shop Health Medium
Health 100 Health Expensive
Sports Life Sport Cheap
Athletics Sport Expensive
我正在尝试编写一个查询,输出属于所有国家都是日本的类别的所有名称(例如,健康和体育类别中的所有商店都在日本)。例如。输出将是:
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子句中或用于聚合函数LINE 3:inner join(select t2.Category,t3.Country)
我不知道为什么我会收到此错误以及如何解决此问题。任何见解都表示赞赏。
我不知道你为什么使用子查询,但结果要求可以通过使用连接获得
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')