我想要LEFT JOIN
,然后按rank
列对显示进行排序,并仅在qty
列大于0时显示项目
SELECT
*
FROM `product`
LEFT JOIN `stock`
ON `product`.`product_id`=`stock`.`pid`
AND `qty` > 1
ORDER BY `product`.`rank` ASC
产品表
product_id
name
rank
price
股票表
pid
price_sale
qty
Product Table
12, Pen, 2, 53.00
13, Pen, 1, 58.00
14, Pen, 3, 25.00
Stock Table
12, 10.00, 5
13, 18.00, 15
我的结果没有出现。
应显示:
12, Pen, 2, 53.00, 12, 10.00, 5
13, Pen, 1, 58.00, 13, 18.00, 15
答案 0 :(得分:3)
使用以下查询
SELECT * FROM `product`
LEFT JOIN `stock`
ON `product`.`product_id`=`stock`.`pid`
WHERE `stock`.`qty` > 0
ORDER BY `product`.`rank` ASC
答案 1 :(得分:1)
AND应该是这样的地方:
SELECT *
FROM `product`
LEFT JOIN `stock` ON `product`.`product_id`=`stock`.`pid`
WHERE `qty` > 1
ORDER BY `product`.`rank` ASC