如何用sql更新set with group

时间:2016-01-14 04:03:01

标签: mysql

我有absen表格,其中包含

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

我希望在SET kondisi='yes'

时更新GROUP BY absen.id='15' AND tglitung='2016-01-14'

如何使用像这样的情况设置更新?

1 个答案:

答案 0 :(得分: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';