I have a table like this
id | item | price | vip
---+--------+--------+-----
0 | tv | 2000 | NULL
1 | tv | 2500 | TRUE
2 | camera| 3000 | NULL
3 | camera| 3500 | TRUE
4 | phone | 1000 | NULL
5 | pen | 2 | NULL
In this table, I have some duplicated entries because I need to store vip price. If normal person visit, I need to show
item | price
------+---------
tv | 2000
camera| 3000
phone | 1000
pen | 2
If vip person comes, then I should show price like
item | price
------+-----------
tv | 2500
camera| 3500
phone | 1000
pen | 2
The last column is Boolean.
I need query to get items. Please help to get the query for this.
Regular customer:
select item, price
from tablename
where vip is NULL
vip customer:
select item, price
from tablename t1
where vip is true
or not exists (select 1 from tablename t2
where t1.item = t2.item
and vip is true)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With