Case

case `gender`
when 'male' then 'boy'
when 'femal' then 'girl'

end


case
when `age` > 20 then 'adult'
when `age` < 20 then 'youth'
end


case 
when `age` is null then 'unknown'
else cast(`age` as CHAR(2))
end

Example

SELECT a.id, a.pic, a.name, 
(
case 
	when b.id is null then '0'
	else '1'
end
) as following
FROM `users` a 
left join follows b on b.target_user_id = a.id and b.user_id = 21 
where a.id <> '21'  
order by following desc, a.created_on desc 
limit 0, 20

 

One thought on “Case

  1. Every weekend i used to visit this website, for the reason that i
    want enjoyment, since this this site conations really fastidious funny information too.

Comments are closed.