다음 SQL 문이 있습니다. 나는에게데이터를 롤업 할 SQL Server 쿼리
first_name | last_name | title | type_1 | type_2 | type_3 | type_4
-----------+------------+--------------+--------+--------+--------+---------
Joe | Kewl | My_report_1 | 1 | 1 | 1 | 0
Sly | Foxx | Other_Rep_1 | 1 | 1 | 0 | 0
불행하게도 :
first_name | last_name | title | type
-----------+-------------+--------------+------
Joe | Kewl | My_Report_1 | 2
Joe | Kewl | My_Report_1 | 3
Joe | Kewl | My_Report_1 | 1
Sly | Foxx | Other_Rep_1 | 1
Sly | Foxx | Other_Rep_1 | 2
내 목표 결과는 다음 표를 얻을 수 있습니다 : 결과는 다음과 같다 Person
, Deliverable
및 DeliverableActions
select
p.first_name, p. last_name, d.title, da.type
from
Deliverable d
right join
Person p on d.person_responsible_id = p.id
right join
DeliverableAction da on da.DeliverableID = d.id
where
d.date_deadline >= @startDate and
d.date_deadline <= @endDate
order by
d.title
의 세 가지 테이블을 조인 내가하는 일을 설명하기 위해 어떤 용어를 모르겠다. '그룹화'와 '집계'를 검색했지만 응답이 없으므로 커뮤니티에 추가합니다. 당신의 도움에 미리 감사드립니다.
당신이case based aggregation
를 사용하거나 당신은 또한 사용할 수 있습니다
'구문이 잘못되었습니다.'= –
에 'case ** when ** da.type ...'이 추가되었으며 –
@ user1571934가 작동합니다. – radar