2016-01-14 62 views
0

更新集與I組有absen表樣柱,如何通過SQL

Absen's table

我查詢它像,

SELECT count(tgl) AS total, absen.id, absen.status, absen.kondisi, 
CASE WHEN (weekday(tgl) <=3) THEN date(tgl + INTERVAL(3 - weekday(tgl)) DAY) 
ELSE date(tgl + INTERVAL(3 +7 - weekday(tgl)) DAY) 
END AS tglitung 
FROM absen 
WHERE absen.status = 'm' 
GROUP BY absen.id, tglitung 

其結果

enter image description here

我想更新e SET kondisi='yes',當GROUP BY absen.id='15' AND tglitung='2016-01-14'

如何使用set更新這種情況?

回答

1

試試這個:

UPDATE absen SET kondisi = 'yes' 
WHERE id = 15 
    AND (CASE WHEN (WEEKDAY(tgl) <=3) THEN DATE(tgl + INTERVAL(3 - WEEKDAY(tgl)) DAY) 
    ELSE DATE(tgl + INTERVAL(3 +7 - WEEKDAY(tgl)) DAY) 
    END) = '2016-01-14';