如何修改我的查询以排除两个特定列?

时间:2016-02-29 11:03:00

标签: mysql sql

所以我在select语句中有两个显示此信息的视图:

--------------------------------------------------------------
| branchID | branchName | staffNo | Full Name | salary | ... |
--------------------------------------------------------------
| ....                                                       |
--------------------------------------------------------------

这是我的问题:

SELECT *
FROM EmployeesAndSalaryByBranch E, CustomersByBranch C
WHERE E.branchID <> 'Headquarters';

现在,我不想从查询结果中删除branchIdbranchName列。一种方法是创建临时表并删除列,但这非常效率低

谢谢!

1 个答案:

答案 0 :(得分:2)

只需从select声明中排除列:

这个concatenate名字和姓氏之间没有空格:

SELECT staffNo, CONCAT(firstName, lastName) AS [Full Name], salary
FROM EmployeesAndSalaryByBranch E, CustomersByBranch C
WHERE E.branchID <> 'Headquarters';

这包括名字和姓氏之间的空格:

SELECT staffNo, CONCAT(firstName, ' ', lastName) AS [Full Name], salary
FROM EmployeesAndSalaryByBranch E, CustomersByBranch C
WHERE E.branchID <> 'Headquarters';