assume the data table relationship:
order order data sheet:
order_id / public_order_id
1 / AAA
2 / BBB
3 / CCC
prod goods data sheet:
order_id / prod_id
1 / 100
1 / 101
1 / 102
2 / 101
2 / 103
3 / 102
3 / 104
Front end display
AAA
BBB
CCC
when I want to exclude an order with a certain prod_id that does not display
suppose I want to rule out that the order does not display if it has prod_id 100s
the front end will exclude AAA and the rest:
BBB
CCC
if prod_id 101
is appended, only CCC will be left (because both AAA and BBB contain 100,101)
CCC
how can I judge this?
SELECT
r.public_order_id,
FROM `order` as r
JOIN `prod` as p ON p.order_id = r.order_id
WHERE p.prod_id != 100
AND p.prod_id != 101
// GROUP BY r.public_order_id
I find that if there is no GROUP BY public_order_id,
assumes how many prod_id the order has, how many public_order_id will be repeated
but if I GROUP BY public_order_id,
he will print out all the AAA,BBB,CCC, but in fact, each order has more than one prod_id, and there are 100,101
that I don"t want. So something will go wrong!
what I want to achieve is
when there is a prod_id in the order that I don"t want, it doesn"t show
. Now, although the order has a prod_id that I don"t want, there are other goods that are not this prod_id, so it shows
charge
Database structure:
SQL sentence
SELECT
r.status,
uo.add_time,
r.public_order_id,
uo.order_id,
u.name as uname,
ss.prod_id
FROM `user_order` as uo
JOIN `order_record` as r ON r.order_id = uo.order_id
JOIN `user` as u ON u.id = r.id
JOIN `stock` as ss ON ss.order_id = r.order_id
AND (ss.prod_id = 115
or ss.prod_id = 120)
WHERE r.status = ""
AND ss.prod_id is null