table **salesrule_coupon**: fileds as the following:
coupon_id code
1 Registered_send_5
2 test
表:salesrule_coupon_usage
的Fileds如下所示:如何用兩個表編寫sql命令?
coupon_id customer_id times_used
1 1 1
1
... 14 ... 1..
現在,我要選擇出times_used
其中code =Registered_send_5
其中CUSTOMER_ID = $ ID。如何編寫sql命令?謝謝你。
以下是我的,但它不能正常工作。
$sql = "SELECT times_used FORM salesrule_coupon_usage as a
left join salesrule_coupon as b on a.coupon_id = b.coupon_id
where b.code = 'Registered_send_5' and customer_id=".'$id.";
,當我把
SELECT times_used FORM salesrule_coupon_usage as a
left join salesrule_coupon as b on a.coupon_id = b.coupon_id
where b.code = 'Registered_send_5' and customer_id=1
在phpMyAdmin。它顯示
您的SQL語法錯誤;檢查與您的MySQL服務器版本相對應的手冊,在第1行使用'salesrule_coupon_usage作爲左加入salesrule_coupon作爲b上的a.co'附近的正確語法。
爲什麼它不工作?你有什麼錯誤?請發帖 –
不校對自己的代碼是一個壞主意。 –