set @n=(select areaid from areas where areaname='江苏省'); prepare stmt from ' select customerid,sum(amount) amt from orders join orderitems using(orderid) join customers b using(customerid) join areas c on b.regionid=c.areaid group by customerid order by amt desc where b.regionid=@n limit?'; set @n1=0.3*(select count(*)from orders); execute stmt using @n1;查询错误
时间: 2023-06-11 20:08:20 浏览: 131
MySQL报错1093 – You can’t specify target table ‘t’ for update in FROM clause, Time: 0
根据你提供的查询语句,我发现其中的`where b.regionid=@n`应该放在`join areas c on b.regionid=c.areaid`之后,因为这是一个连接条件。另外,因为使用了`prepare`语句,需要在最后加上`deallocate prepare stmt;`来释放资源。修改后的查询语句如下:
```
set @n=(select areaid from areas where areaname='江苏省');
prepare stmt from 'select customerid,sum(amount) amt from orders join orderitems using(orderid) join customers b using(customerid) join areas c on b.regionid=c.areaid where b.regionid=@n group by customerid order by amt desc limit ?';
set @n1=0.3*(select count(*)from orders);
execute stmt using @n1;
deallocate prepare stmt;
```
你可以尝试一下这个修改后的查询语句是否可以正确执行。
阅读全文