Ho bisogno di unire più tabelle, selezionare i conteggi da tabelle diverse e raggruppare per una colonna in una query. Questo è come farei questo a parte:Unire più tabelle, selezionare i conteggi da diverse tabelle e raggruppare per una colonna in una query
select c.CommunityName, SUM(case when m.ListKey = c.ListKey then 1 else 0 end) as Posts
from Community c with(NOLOCK)
join messages_ m with(NOLOCK)
on c.ListKey = m.ListKey
group by c.CommunityName
select c.CommunityName, SUM(case when b.CommunityKey = c.CommunityKey then 1 else 0 end) as Blogs
from Community c with(NOLOCK)
join Blog b with(NOLOCK)
on c.CommunityKey = b.CommunityKey
group by c.CommunityName
select c.CommunityName, SUM(case when ce.CommunityKey = c.CommunityKey then 1 else 0 end) as Events
from Community c with(NOLOCK)
join CalendarEvent ce with(NOLOCK)
on c.CommunityKey = ce.CommunityKey
where ce.StartDateTime >= GETDATE()
group by c.CommunityName
o semplicemente
select c.CommunityName, COUNT(*)
from Community c with(NOLOCK)
join messages_ m with(NOLOCK)
on c.ListKey = m.ListKey
group by c.CommunityName
select c.CommunityName, COUNT(*)
from Community c with(NOLOCK)
join Blog b with(NOLOCK)
on c.CommunityKey = b.CommunityKey
group by c.CommunityName
select c.CommunityName, COUNT(*)
from Community c with(NOLOCK)
join CalendarEvent ce with(NOLOCK)
on c.CommunityKey = ce.CommunityKey
where ce.StartDateTime >= GETDATE()
group by c.CommunityName
Non ci sono più tabelle, alcuni che richiedono ulteriore unisce ... Per favore qualcuno può aiutarmi?
Non è possibile unirle tutte insieme, aggiungendo un campo di testo statico per distinguere ciascun gruppo? – Joe
Sono ancora un baby wizard SQL;) Controllerò UNION. Grazie! – HLkatie
Quale dovrebbe essere il risultato? somma di tutti i conteggi di domande diverse? – Lobo