私は、アポイントメントタイプ列 (nvarchar) を持つテーブル、セッションを持っています。aptType は、3 つの値 (hour、halfhour、pair) のいずれかです。
必要なのは、クライアント名、時間数、30 分数、ペア数です。
したがって、データは次のようになります
bob | Hour
bob | Hour
bob | halfhour
bob | halfhour
bob | halfhour
bob | Pair
私が欲しいのは
bob | 2 | 3 | 1
このテーマのバリエーションを試しました
select c.firstname,
count(shour.clientid),
count(shalfhour.clientid),
count(sHour.clientid)
From Client as c
left outer join [session] as sHour on c.Entityid = shour.ClientId
left outer join [session] as sHalfHour on c.Entityid = sHalfHour.ClientId
left outer join [session] as sPair on c.Entityid = sPair.ClientId
where c.entityid =1 and (shour.appointmentType = 'Hour' or sHalfHour.appointmentType = 'HalfHour')
group by c.firstname
クライアント 1 のデータは、彼が 35 時間の apttypes を持ち、残りは 0 であることです。
上記を行うと、
bob | 1135 | 1135 | 1135
where を an に変更すると、または 0 行が返されます。
とにかく私がやろうとしていることをすることはありますか?