简体   繁体   中英

CASE Statement in codeigniter query

I have following table of students

Attendance is of the month of November 2011

    date       absentperiod         name         

    2011-11-01      1               x        
    2011-11-01      5               x        
    2011-11-01      5               y        
    2011-11-01      1               z        

How to write sql query to find status? I am doing it in php.

I want to get output for employee x - absent , y - half day , z- half day

Students absent in period 1 and 5 should be absent Students absent in period 1 or 5 should be HALF DAY

Try this:

select date,
  first_period,
  fifth_period,
  name,
  case when first_period != fifth_period 
  then 'Half day' 
  else first_period end status
from my_table;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM