我正在努力使以下工作:
# prev
SELECT klha.buyerID < PARAMETER_1
FROM agents AS v
LEFT JOIN seller_authorized AS klhs
ON klhs.agent= v.agentID
AND klhs.iln = v.seller
AND v.`status` = 'auth'
LEFT JOIN cust_list AS klha
ON klha.buyerID = klhs.userID
AND klha.accountNo = klhs.accountNo
WHERE v.iln = PARAMETER_2
AND klhs.acccountNo IS NOT NULL
ORDER BY klha.buyerID
LIMIT 1
;
结尾
左连接正在工作,因为我在另一个过程中使用它们来选择所有相关记录。问题在于我尝试选择上一条记录。
我传入了一个buyerID,需要取回上一条记录的ID。
问题:
谁能指出正确的语法?
编辑:
如果我在 MySQL 中运行它,我会得到“0”作为结果集
谢谢!
解决方案:
让它像这样工作:
# prev
SELECT klha.buyerID
FROM agents AS v
LEFT JOIN seller_authorized AS klhs
ON klhs.agent= v.agentID
AND klhs.iln = v.seller
AND v.`status` = 'auth'
LEFT JOIN cust_list AS klha
ON klha.buyerID = klhs.userID
AND klha.accountNo = klhs.accountNo
WHERE v.iln = PARAMETER_2
AND klhs.acccountNo IS NOT NULL
AND klha.buyerID < PARAMETER_1
ORDER BY klha.buyerID
LIMIT 1
;
比想象的容易:-) 谢谢@Henrique Ordine