Customers 테이블과 Purchases 테이블과 같은 두 개의 테이블이 있습니다. 그리고 나는 1 년 이상 구매 한 고객을 얻으려고 노력합니다. 그래서 이것은 현재의 쿼리입니다그룹으로 집계 값을 얻는 올바른 방법
select c.name, c.email
from customers c inner join purchases p
on c.customerid = p.customerid
where p.year = 2002
group by c.name, c.email
문제는 내가 지금하고있는 문제는 내가 원하는 것을 정확히 구매하지 못하게하는 것입니다. 그래서 다음과 같이 편집하고 싶습니다 :
select c.name, c.email
from customers c inner join purchases p
on c.customerid = p.customerid
where p.year = 2002 and p in
(select p.customerid, count(p.*) as total
from purchases
where total > 1
group by p.customerid)
group by c.name, c.email
그리고이 쿼리는 문법 오류로 가득 찼습니다. 어떤 사람이 나에게 아이디어를 주도록 도와주세요.
+ 1 감사 등이있다. 그러한 편리 성명 –