简体   繁体   English

表示 Last_Name + First_Name 有一个具有特定值的记录

[英]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.

相关问题 通过First_Name和/或Last_Name查询sql表 - query sql table By First_Name and/or Last_Name 如有空格,如何将NAME分为3个不同的字段FIRST_NAME,MIDDLE_NAME和LAST_NAME - How to split NAME into 3 different fields FIRST_NAME, MIDDLE_NAME & LAST_NAME when there is a space 具有名称,名字和姓氏的PostgreSQL多表查询 - PostgreSQL multi-table query with name, first_name, and last_name 如何使用sql查询组合first_name和last_name? - How to combined first_name and last_name using sql query? 使用 Reg_exp 从电子邮件预言机中提取名字和姓氏 - Extracting First_name & Last_name from email oracle using Reg_exp 在本地数据库中存储 OAuth 用户信息(用户名、名字、姓氏等) - Storing OAuth user info (username, first_name, last_name etc) in local database PHP-如何在登录后获取正确的名字和姓氏? - PHP - How to get correct first_name and last_name after login? 编译时:INSERT或IGNORE INTO联系人(姓,名,用户名,电话号码) - while compiling: INSERT OR IGNORE INTO contacts(last_name, first_name, user_id, phoneno) 将 first_name 和 last_name 列中的名称截断为 1 个字符的最有效方法是什么? - What's the most efficient way of truncating the names in a first_name and last_name column to 1 character? 查询以使用外键获取行值(first_name 和 last_name) - Query to fetch row values (first_name & last_name) using foreign key
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM