0
select * from car where carbrand = 'bmw' limit 1
union
select * from car where carbrand = 'mercedez'

是否可以在不使用联合的情况下组合此查询?

4

1 回答 1

5

尝试

SELECT * FROM car WHERE carbrand IN ('bmw', 'mercedez') GROUP BY carbrand 

编辑:

SELECT * FROM car WHERE carbrand IN ('bmw', 'mercedez') GROUP BY CASE WHEN carbrand = 'bmw' THEN carbrand  ELSE car_id END

看看car_id上面的 ELSE 条件,把它放在你各自的 id 上。

于 2012-08-26T07:05:28.917 回答