göreSQL Sayısı birden çok sütun I verilerini sorgulamak için gereken 2 veri tablolar
Machine_ID Machine_name
101 Computer1
202 Computer2
303 Computer3
404 Computer4
İkinci tabloda:
Machine_ID Event_ID Event_date
101 1 03/15/2016
101 1 03/14/2016
101 2 03/15/2016
101 1 03/13/2016
102 1 03/15/2016
102 2 03/15/2016
102 1 03/14/2016
103 2 03/15/2016
103 2 03/14/2016
104 1 03/15/2016
Bir uyumlu olduğu sorgu çıktısını gerekir ve tutan bilgi:
Machine_ID,
Machine_Name,
Count(Machine_ID) where Event_ID='1'
Count(Machine_ID) where Event_ID='2'
Ben sorguyu yazmak ancak doğru sözdizimi için bir kayıp am için çeşitli yollar denedi.
Bu çalışmıyor ama gidiyorum bir fikir verecektir: olmalı
Select M.Machine_ID, M.Machine_Name,
count(Machine_ID) where E.Event_ID='1' and Machine_ID='101',
count(Machine_ID) where E.Event_ID='2' and Machine_ID='101'
from Machines M
join Events E on M.Machine_ID = E.Machine_ID
verilen verilere dayalı bu çıktı:
101 Computer1 3 1
Olası yinelenen [Bir SQL sorgusuyla birden çok sayı nasıl alınır?] (Http://stackoverflow.com/questions/12789396/how-to-get-multiple-counts-with-one-sql-query) –