我们应该使用什么查询? [英] What query should we use?

查看:69
本文介绍了我们应该使用什么查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有一个表As emp_id | emp_name | mgr_id,其中emp_id - > enployee id和mgr_id - > manager-id其中manager也是一名员工,所以我想要一个查询来选择emP_name,其状态为employee或manager。

Suppose we have a table As emp_id | emp_name | mgr_id where emp_id--> enployee id and mgr_id-->manager-id where manager is also an employee so I want a query to select the emP_name with their status of employee or manager.

推荐答案

假设我上面做出的假设很简单:

Assuming the assumptions I made above, it's pretty easy:
SELECT emp_name as [Employee Name], 
       CASE WHEN mgr_id IS NULL THEN 'Employee' ELSE 'Manager' END as [Type] 
FROM myTable


这篇关于我们应该使用什么查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆