SQL QUERY :: CONDITIONS IN ONE COLUMN -
i want have 3 if/case conditions stated on same column
select u.username, u.fullname, u.email, (if u.status = "done" , ui.itemtotal != "null" 0 if u.status = "done" , ui.itemtotal = "null" 1 if u.status != "done" , ui.itemtotal != "null" 2) "item.status" list_users u bring together list_items ui on ui.userid = u.id
use case
statement:
select u.username, u.fullname, u.email, case when u.status = 'done' , ui.itemtotal != 'null' 0 when u.status = 'done' , ui.itemtotal = 'null' 1 when u.status != 'submitted' , ui.itemtotal != 'null' 2 end "item.status" list_users u bring together list_items ui on ui.userid = u.id
also careful when checking null
values. assume checking string value of null
. if not, utilize is null
or is not null
:
case when u.status = 'done' , ui.itemtotal not null 0 when u.status = 'done' , ui.itemtotal null 1 when u.status != 'submitted' , ui.itemtotal not null 2
sql
No comments:
Post a Comment