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.
精彩评论