我根据数据库的位置ID和数量检索数据超过五项,但我想要特定的位置ID检索数量超过0项的项目
这是我的疑问:
SELECT DISTINCT(warehouses.item_id), SUM(warehouses.qty) AS qty, items.gender_id, items_dept.desc, items_dept.dept_id, items.msrp,items.rtp
FROM `warehouses`
JOIN `items`
ON items.item_id = warehouses.item_id
JOIN `items_dept`
ON items_dept.dept_id = items.dept_id
WHERE items.gender_id IN (3,5,6)
AND qty > 5
AND warehouses.wrhs_id IN (20,21,22,23,24,25,26,27,28,29,30,31,32,38,40,44,47,49,55,60,61)
AND items.dept_id = :catId
AND items.rtp BETWEEN :priceX AND :priceY
GROUP BY warehouses.item_id
ORDER BY warehouses.item_id ASC
我想要wrhs_id(44)数量不超过5但超过0
答案 0 :(得分:0)
在SQL中,您可以使用LIMIT参数指定返回项的限制,但如果检索0项则表示您输入了错误或数据库中没有数据
答案 1 :(得分:0)
试试这个:
SELECT DISTINCT(warehouses.item_id), SUM(warehouses.qty) AS qty, items.gender_id, items_dept.desc,items_dept.dept_id,items.msrp,items.rtp
FROM `warehouses`
JOIN `items` ON items.item_id = warehouses.item_id
JOIN `items_dept` ON items_dept.dept_id = items.dept_id
WHERE items.gender_id IN (3,5,6)
AND qty > 0
AND warehouses.wrhs_id = 44
AND items.dept_id = :catId
AND items.rtp BETWEEN :priceX AND :priceY
GROUP BY warehouses.item_id
ORDER BY warehouses.item_id ASC
答案 2 :(得分:0)
SELECT DISTINCT(warehouses.item_id), SUM(warehouses.qty) AS qty, items.gender_id, items_dept.desc, items_dept.dept_id, items.msrp,items.rtp
FROM `warehouses`
JOIN `items`
ON items.item_id = warehouses.item_id
JOIN `items_dept`
ON items_dept.dept_id = items.dept_id
WHERE items.gender_id IN (3,5,6)
AND ((
qty > 5
AND
warehouses.wrhs_id IN (20,21,22,23,24,25,26,27,28,29,30,31,32,38,40,47,49,55,60,61)
)
OR (
qty > 0
AND
warehouses.wrhs_id = 44
)
)
AND items.dept_id = :catId
AND items.rtp BETWEEN :priceX AND :priceY
GROUP BY warehouses.item_id
ORDER BY warehouses.item_id ASC