需要以下情况的SQL查询

mysql sql oracle

52 观看

3回复

27 作者的声誉

Car      Owner

'honda','nepolian'
'benz','nepolian'
'nissan','nepolian'
'lexus','sivaji'
'honda','sivaji'
'benz','sivaji'
'nissan','sivaji'
'landrover','kumar'
'kiamotors','kumar'
'honda','kumar'
'ferrari','vivek'
'suziki','vivek'

我想选择拥有那不勒斯人拥有的所有汽车的车主?

请帮我解决这个问题!

作者: Thiruvettai Athithiyan S 的来源 发布者: 2017 年 9 月 15 日

回应 3


0

1 作者的声誉

您是说要让列中的所有汽车与Cars列中的所有者Owner相等nepolian吗?在一张桌子内?

除非有其他事情(我希望更复杂),否则您应该能够做到:

SELECT car
FROM *name of table*
WHERE owner = 'nepolian';
作者: Varun Prabhakar 发布者: 2017 年 9 月 15 日

1

80335 作者的声誉

不知道为什么要同时标记mysql和oracle,但这是在mysql中的方法(未经测试):

select owner
from yourtable
where car in (select car from yourtable where owner='nepolian')
and owner <> 'nepolian'
group by owner
having group_concat(car order by car)=(select group_concat(car order by car) from yourtable where owner='nepolian');

如果一个人可以拥有多辆相同的汽车,而您又不想要求每辆汽车具有相同的编号,请稍作更改:

having group_concat(distinct car order by car)=(select group_concat(distinct car order by car) from yourtable where owner='nepolian');
作者: ysth 发布者: 2017 年 9 月 15 日

0

31 作者的声誉

select t.owner from (
  select count(t1.car) as car_count, t1.owner from tableName t1
  join tableName t2 on t2.car = t1.car
  where t2.owner = 'nepolian' and t1.owner <> 'nepolian'
  group by t1.owner )
t where t.car_count = (
  select tmp.car_count from (
         select count(car) as car_count, owner from tableName
         where owner = 'nepolian' group by owner
  ) tmp
)

也许对您有帮助!执行mysql就可以了!如果上面的sql可行,并且速度不是很慢,请给我消息!

作者: Dalton 发布者: 2017 年 9 月 17 日
32x32