开发者

Help with SELECT DISTINCT

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜