我需要为一个数据集获取多个查询值

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

我想根据审计创建报告 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'

这是我使用的查询,但我需要将这些单独的 table 合并为一个 table,如果这些单元格中只有“1”,则应计算计数。但我的 table 也有“0"s but it consider them as values and counts "0” 个单元格this is the tabel now

只需使用 GROUP BY

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

改为尝试分组

 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

这将 return 您想要的结果。

编辑:我之前误解了你的问题。如果要统计一个人在 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