我有两张桌子:一张是 Tour,另一张是 ReservedTour。表格的列是:
Tour | ReservedTour
===========|=============
id | id
city | Tid
capacity | number
timeout | .
. | .
. | .
. |
========== |======
我写了一条SQL语句,例如
select *, (select sum(rt.`number`) from ReservedTour as rt where rt.`Tid`=t.id GROUP BY rt.`Tid`) as total
from Tour as t
where City = 'alahom' and '1400-12-13' <= t.`timeout` and 4 < t.`Capacity`- total;
但这有一个错误——总数不正确。
我该如何纠正?