SELECT tblorder.fld_userid
FROM `tblordereditems`
inner JOIN tblorder ON tblorder.fld_id = tblordereditems.fld_order_id
where (SELECT sum( tblordereditems.fld_product_quantity )FROM tblordereditems inner JOIN tblorder ON tblorder.fld_id =tblordereditems.fld_order_id GROUP BY tblorder.fld_userid)>5
这是我的查询,但会抛出错误。可以提供任何身体帮助吗?谢谢
这里有三张表。
tbluser的字段fld_id是tblorder的外键,如fld_userid。
tblorder的fld_id是tblordereditems的外键,如fld_order_id,我得到的结果是fld_userid已经订购了超过5个数量的产品,即。 fld_product_quantity的总和由tblorder.fld_userid
答案 0 :(得分:1)
它返回的行数超过1行,因为您正在请求所有用户的计数。
尝试:
Select tb1.fld_userid
FROM `tblordereditems` tbi1
inner JOIN tblorder tb1 ON tb1.fld_id = tbi1.fld_order_id
where (
SELECT sum( tbi2.fld_product_quantity )
FROM tblordereditems tbi2 inner JOIN tblorder tb2 ON tb2.fld_id =tbi2 .fld_order_id
where tb2.fld_userid = tb1.fld_userid
)>5