简体   繁体   中英

i need to get multiple query values to a one data set

i want to create a report from an audit table this is the audit table, i need to get the count of address, tele, and AssName(AssociationName) of each and every person specificly

 select count(tele),count(AssName),count(Address) from Audit where name='ben'   
 select count(tele),count(AssName),count(Address) from Audit where name='nik'
 select count(tele),count(AssName),count(Address) from Audit where name='josh'

this is the query i used but i need these individual tables into one table and the count should be calculated if only "1" is in these cells. but my table has "0"s but it consider them as values and counts "0" cells too this is the tabel now

try a group by instead

 SELECT 
  name,
  count(tele),
  count(AssName),
  count(Address) 
  FROM Audit 
    GROUP BY name
Select name , count (Assname), count (Address), count(tele)
from Audit
GROUP by Name

This would return your desired result.

Edit: I misunderstood your question earlier. You need to add group by the name if you want to count the number of each name a person is in the table.

 SELECT 
 name,
 sum(case when tele is not null then 1 else 0 end) tele,
 sum(case when Assname is not null then 1 else 0 end) Assname,
 sum(case when Address is not null then 1 else 0 end) Address
 FROM Audit
 GROUP BY name

只需使用GROUP BY

select name, count(tele),count(AssName),count(Address) from Audit group by name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM