我想计算人们报名参加年度会议的次数,但我想只计算一次每次会议(有时人们会在一次会议上报名参加其他活动,因此他们的记录中的活动会显示多个“出席“单一会议”。答案表应在“#conf”字段中显示不超过2个:
SELECT distinct n.id, n.last_name, n.first_name, count(n.id) as "# of conf" from name n
join activity a
on n.id = a.id
where a.product_code in ('conf_12','conf13') and n.id <>'' and n.last_name <>''
group by n.id, n.last_name, n.first_name
order by n.last_name
我很感激我能得到任何帮助!
答案 0 :(得分:1)
请尝试使用COUNT(DISTINCT...)
表格中product_code
列的activity
条款,如下所示:
SELECT
n.id, n.last_name, n.first_name,
count(distinct a.product_code) as "# of conf"
from
name n
join activity a
on n.id = a.id
where
a.product_code in ('conf_12','conf13')
and n.id <>''
and n.last_name <>''
group by
n.id, n.last_name, n.first_name
order by
n.last_name
COUNT(DISTINCT somecolumn)
为您提供每个特定查询组中somecolumn
的不同值的计数。