开发者

Help with SELECT DISTINCT

开发者 https://www.devze.com 2023-03-14 07:05 出处:网络
I have a plans table: tariff|monthly_cost -------------------------- Lion,15.00 Lion,20.00 Cat,15.开发者_运维技巧00

I have a plans table:

tariff      |   monthly_cost
--------------------------
  Lion      ,    15.00
  Lion      ,    20.00
  Cat       ,    15.开发者_运维技巧00
  Cat       ,    20.00
  Cat Extra ,    20.00
  Cat Extra ,    30.00

to run this SQL query:

SELECT DISTINCT monthly_cost FROM plans;

Which will be:

monthly_cost
------------
15.00
20.00
30.00

I wanted the result to appear like this:

tariff      |   monthly_cost
--------------------------
            ,    15.00
            ,    20.00
  Cat Extra ,    20.00
  Cat Extra ,    30.00

How can that be done?


select distinct null, monthly_cost
from plans
where tariff not like 'Cat Extra'
union
select tariff, monthly_cost
from plans
where tariff like 'Cat Extra'

Dirty, but efficient.

0

精彩评论

暂无评论...
验证码 换一张
取 消