有人可以帮忙解决此问题吗?我尝试了几乎没有运气的事情。
我有以下MySQL查询,它会吐出以下错误
错误: 'on clause'
中的未知列'SR.sales_rec_id'QUERY:
SELECT
SYSKEY.cri_sr_id,
SR.sales_rec_id,
SYSKEY.adnum,
charge,
SYSKEY.cancelsale,
paymentdue,
merchant,
paymentnum,
authorization as authcode,
CONCAT(lastname,', ',firstname,' ',middleinitial) as customer,
CONCAT(replname,', ',repfname) as repname,
FROM CRI_SR_KEYS as SYSKEY
INNER JOIN SALES_PENDING as SPEND on SPEND.sales_rec_id=SR.sales_rec_id
INNER JOIN SALES_RECORD as SR on SR.cri_sr_id=SYSKEY.cri_sr_id
LEFT JOIN CLIENT_INFO as CI on CI.client_id = SYSKEY.clientid
LEFT JOIN SALES_REPS as REP on SR.rep_id=REP.repid
WHERE SPEND.authorization NOT LIKE '000000' AND paymentdue LIKE CURDATE()
ORDER BY adnum ASC LIMIT 0,5000
答案 0 :(得分:2)
重新排列联接的顺序,以便在您尝试使用之前SR
有别名:
SELECT
SYSKEY.cri_sr_id,SR.sales_rec_id,
SYSKEY.adnum,charge,
SYSKEY.cancelsale,paymentdue,merchant,paymentnum,authorization as authcode,
CONCAT(lastname,', ',firstname,' ',middleinitial) as customer,
CONCAT(replname,', ',repfname) as repname
FROM CRI_SR_KEYS as SYSKEY
INNER JOIN SALES_RECORD as SR on SR.cri_sr_id=SYSKEY.cri_sr_id
INNER JOIN SALES_PENDING as SPEND on SPEND.sales_rec_id=SR.sales_rec_id
LEFT JOIN CLIENT_INFO as CI on CI.client_id = SYSKEY.clientid
LEFT JOIN SALES_REPS as REP on SR.rep_id=REP.repid
WHERE SPEND.authorization NOT LIKE '000000' AND paymentdue LIKE CURDATE()
ORDER BY adnum ASC LIMIT 0,5000
在SELECT子句中repname
之后还有一个逗号,但这可能只是一个错字。
答案 1 :(得分:1)
如果列SALES_RECORD.sales_rec_id
确实存在,请重新排序JOIN
语句:
FROM CRI_SR_KEYS as SYSKEY
/* Move this above SALES_PENDING to SR */
INNER JOIN SALES_RECORD as SR on SR.cri_sr_id=SYSKEY.cri_sr_id
INNER JOIN SALES_PENDING as SPEND on SPEND.sales_rec_id=SR.sales_rec_id
LEFT JOIN CLIENT_INFO as CI on CI.client_id = SYSKEY.clientid
LEFT JOIN SALES_REPS as REP on SR.rep_id=REP.repid