我的员工表如下:
+-------------+---------+------------------+
| employee_id | phone | dept |
+-------------+---------+------------------+
| 1 | 7738474 | marketing |
| 2 | [null] | marketing |
| 3 | 9938475 | customer service |
| 4 | 4233474 | customer service |
| 5 | 1738477 | marketing |
| 6 | [null] | marketing |
| 7 | [null] | customer service |
+-------------+---------+------------------+
我想如果市场部有空电话值,他们不显示,如果客户服务部,他们显示所有的价值,即使电话是空的
+-------------+---------+------------------+
| employee_id | phone | dept |
+-------------+---------+------------------+
| 1 | 7738474 | marketing |
| 3 | 9938475 | customer service |
| 4 | 4233474 | customer service |
| 5 | 1738477 | marketing |
| 7 | [null] | customer service |
+-------------+---------+------------------+
有没有不使用union的查询?
select * from employee where dept ='customer service'
union ALL
select * from employee where dept = 'marketing' and phone is not null
1条答案
按热度按时间iaqfqrcu1#
这听起来像是相对简单的过滤: