gufran gufran - 2 months ago 7
SQL Question

how to update table with multiplication function?

when i tried update my table with this query

update sekolah set [rata-rata] =
(select ([total siswa]*12) from sekolah
where [class]='7IPA' and month([Date]) = 08)
where [class]='7IPA' and month([Date]) = 08


a message is :


Subquery returned more than 1 value. This is not permitted when the
subquery follows =, !=, <, <= , >, >= or when the subquery is used as
an expression.


update
my table is sekolah

my field is :

class
month
total siswa
rata-rata

Answer

If both are same table then it will be helpful:

UPDATE s SET s.rata-rata = (s.[total siswa]*12)
FROM sekolah s
where s.class='7IPA' and month(s.Date) = 08 

OR

UPDATE sekolah SET 
rata-rata = ([total siswa]*12) WHERE class='7IPA' and month(Date) = 08
Comments