我在制定法律聲明時遇到了麻煩,使已發貨(sp)超過500個單位的供應商的狀態加倍。 我一直想:使用SQL中的更新中的JOIN加入
update s
set s.status = s.status * 2
from s join sp
on (sp.sno = s.sno)
group by sno
having sum(qty) > 500;
但是我從MySQL得到這個錯誤:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'from s join sp on (sp.sno = s.sno) group by sno having sum(qty) > 500' at line 1
有沒有人有什麼錯此查詢任何想法?這是我的模式:
create table s
(sno char(5) not null,
sname char(20) not null,
status smallint,
city char(15),
primary key (sno)
);
create table p
(pno char(6) not null,
pname char(20) not null,
color char(6),
weight smallint,
city char(15),
primary key (pno)
);
create table sp
(sno char(5) not null,
pno char(6) not null,
qty integer not null,
primary key (sno, pno)
);
該組可能會導致該問題。 – 2010-04-28 03:09:08
有沒有其他方法可以得到與沒有group by子句的having子句相同的效果? – SDLFunTimes 2010-04-28 03:11:30