在pubs
数据库中,我想找出订单上有多个标题的商店。我已加入表格,但我无法理解用于查找具有多个标题的订单的逻辑
SELECT
title, stores.stor_name, S.ord_num, S.qty
FROM
sales S
JOIN
titles T ON (S.title_id = T.title_id)
JOIN
stores ON (S.stor_id = stores.stor_id)
就像是
SELECT
title, stores.stor_name, S.ord_num, S.qty
FROM
sales S
JOIN
titles T ON (S.title_id = T.title_id)
JOIN
stores ON (S.stor_id = stores.stor_id)
where S.ord_num in (
SELECT
S1.ord_num
FROM
sales S1
JOIN
titles T1 ON (S1.title_id = T1.title_id)
JOIN
stores st ON (S1.stor_id = st.stor_id)
group by S1.ord_num
having count( distinct title)>1
)