如何使用update和select、group、having?

2uluyalo  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(282)

我有这个选择命令

select emp_code, time_date, time_remarks, sum(Tot_hrs) as vTotalHrs 
FROM c04 
WHERE co_code='APPLE'
    and time_date>='01-APR-2020' 
group by emp_code, time_date, time_remarks 
having sum(Tot_hrs)>24

使用此select命令,time\备注为空。我想把时间更新到一个特定的值。我该怎么做?我试过用

UPDATE c04 set TIME_REMARKS = '24more' (//above select command)

但它只是更新了整个table。有人能告诉我哪里出错了吗

hc2pp10m

hc2pp10m1#

这是假设您的emp\ U代码是唯一的id:

UPDATE    c04
SET       '24more' = time_remarks
WHERE     emp_code IN (select    emp_code
                       FROM      c04 
                       WHERE     co_code='APPLE'
                             and time_date>='01-APR-2020'
                             AND time_remarks IS NULL
                       group by  emp_code, 
                                 time_date, 
                                 time_remarks 
                       having    sum(Tot_hrs)>24)

相关问题