나는 한동안이 일에 매달 렸습니다. 그것은 실험실이며 마지막 질문입니다. 나는 위에 열거 한 쿼리를 조합하여 컴퓨터만을 제공하는 공급 업체를 찾습니다. 어떤 도움을 주셔서 감사합니다.트럭 및 컴퓨터만을 제공하는 공급 업체의 이름
컴퓨터와 트럭을 공급하는 공급 업체 만 필요합니다.
나는 한동안이 일에 매달 렸습니다. 그것은 실험실이며 마지막 질문입니다. 나는 위에 열거 한 쿼리를 조합하여 컴퓨터만을 제공하는 공급 업체를 찾습니다. 어떤 도움을 주셔서 감사합니다.트럭 및 컴퓨터만을 제공하는 공급 업체의 이름
컴퓨터와 트럭을 공급하는 공급 업체 만 필요합니다.
이것은 귀하가 제공 한 것, 여기에 해결책에서 컴퓨터와 트럭,하지만
with dat
as
(
select 'Toronto' Supp_id,'Computer' thename union all
select 'Toronto' Supp_id,'Truck' thename union all
select 'Toronto' Supp_id,'Furniture' thename union all
select 'Ottawa' Supp_id,'Computer' thename union all
select 'Ottawa' Supp_id,'Truck' thename union all
select 'Montana' Supp_id,'Furniture' thename union all
select 'Idaho' Supp_id,'Computer' thename union all
select 'John' Supp_id,'Truck' thename union all
select 'John' Supp_id,'Furniture' thename union all
select 'Boris' Supp_id,'Computer' thename union all
select 'Boris' Supp_id,'Truck' thename union all
select 'Harold' Supp_id,'Furniture' thename union all
select 'Yelson' Supp_id,'Furniture' thename
)
select Supp_ID from dat where thename = 'Computer'
intersect
select Supp_ID from dat where thename = 'Truck'
except
select Supp_ID from dat where thename not in ('Truck','Computer')
아무것도를 공급하는 공급 업체를 제공합니다.
SELECT tp.name,
ts.supp_ID
FROM Tb_Supplier ts
inner join tb_offers tb on tb.supp_id = ts.supp_id
inner join tb_prodcut tp on tp.prod_id = tb.prod_id
WHERE ts.supp_ID not in (select ts.supp_ID
from Tb_Supplier ts
inner join tb_offers tb on tb.supp_id = ts.supp_id
inner join tb_prodcut tp on tp.prod_id = tb.prod_id
where tp.product not in ('computers', 'truck')
)
공급자가 컴퓨터 및 트럭 이외의 다른 항목을 제공하는 경우 쿼리는 여전히 OP가 원하는 것이 아닌 공급자를 선택합니다. – Eric
설명해 주셔서 감사합니다. 필요한 결과를 얻는 하위 쿼리를 추가했습니다. @ 에릭 –
이것은 "관계형 부"
그룹화를 요구하고 집계를 비교하여, 예를 들어 데이터를 통해 한 PAS와 "ONLY"요구하는 다수의 과제를 해결
select Supp_ID
from yourdata
group by Supp_id
having sum(case when product_name not in ('Truck','Computer') then 1 else 0 end) = 0
and count(distinct product_name) = 2
;
이러한 변형은 : 다른 제품이 있으면
select Supp_ID
from yourdata
group by Supp_id
having sum(case when product_name not in ('Truck','Computer') then 1 else 0 end) = 0
and min(product_name) = 'Computer'
and max(product_name) = 'Truck'
;
합() 최소 및 최대 다음
가대안 2 개 제품 같아야 다음 <> 0 되고 고려해야 할 제품이 2 개 이상있는 경우 수정하기 쉽습니다.
참조 : Divided We Stand: The SQL of Relational Division (조 셀코)
에서 오는 supp_ID 않는 열입니다. 나는 TB_offers를 가정한다 –
또한 부울이 있어야하고 AND 부울은 –
이어야한다 맞다 –