我写了以下查询:
SELECT order_id
FROM oc_order
WHERE customer_id=7
AND order_status_id=5
这里customer_id 7是硬编码的。而不是硬编码我必须从表中获取id我将如何得到它?
每当客户登录时,表格都会更新
答案 0 :(得分:0)
使用Sub-Query
SELECT order_id
FROM oc_order
WHERE customer_id=(select customer_id from customer where ..)
AND order_status_id=5
考虑到您有Customer
表,其中存储了新的customer_id
答案 1 :(得分:0)
或INNER JOIN
SELECT o.order_id
FROM oc_order o
INNER JOIN customer c ON c.customer_id = o.customer_id
AND o.order_status_id = 5
答案 2 :(得分:0)
试试这个
SELECT order_id
FROM oc_order
WHERE customer_id in (SELECT customer_id
FROM oc_order)
AND order_status_id=5