[英]Indicate a Last_Name + First_Name has one record with specific value
In this code, the results are: In our case, I would like to know which row does not have a 1 in the column is_primary_mo, in our case TANNE I would want a column 'NP' as BANTT has a record with 1.在这段代码中,结果是:在我们的例子中,我想知道 is_primary_mo 列中哪一行没有 1,在我们的例子中 TANNE 我想要一个列“NP”,因为 BANTT 有一个记录为 1。
last_name First_Name is_primary_mo street_address_1
8712 BANTT 1 Center 1
8712 BANTT 0 Center A
8713 TANNE 0 Center 2
8713 TANNE 0 Center 5
select b.last_name, b.first_name, a.is_primary_mo, a.street_address_1
from staff_office_demographics_byprimary_view a
inner join staff_view b
on a.staff_id = b.staff_id
order by b.last_name, b.last_name
Your exact desired result is unclear to me but I hope the below gets you going in the right direction:我不清楚您确切想要的结果,但我希望以下内容能让您朝着正确的方向前进:
Get firstname and lastname where there is at least one record with is_primary_mo = 1 in staff_office_demographics_byprimary_view:获取在 staff_office_demographics_byprimary_view 中至少有一条 is_primary_mo = 1 的记录的名字和姓氏:
select b.last_name, b.first_name
from staff_office_demographics_byprimary_view a
inner join staff_view b
on a.staff_id = b.staff_id
group by b.last_name, b.first_name
having SUM(a.is_primary_mo) > 0
order by b.last_name, b.last_name
Get firstname and lastname where there is exactly one record with is_primary_mo = 1 in staff_office_demographics_byprimary_view:获取在 staff_office_demographics_byprimary_view 中只有一条 is_primary_mo = 1 的记录的名字和姓氏:
select b.last_name, b.first_name
from staff_office_demographics_byprimary_view a
inner join staff_view b
on a.staff_id = b.staff_id
group by b.last_name, b.first_name
having SUM(a.is_primary_mo) = 1
order by b.last_name, b.last_name
Get firstname and lastname where there is no record with is_primary_mo = 1 in staff_office_demographics_byprimary_view:获取staff_office_demographics_byprimary_view中没有is_primary_mo = 1记录的名字和姓氏:
select b.last_name, b.first_name
from staff_office_demographics_byprimary_view a
inner join staff_view b
on a.staff_id = b.staff_id
group by b.last_name, b.first_name
having SUM(a.is_primary_mo) = 0
order by b.last_name, b.last_name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.