我的Employee
表包含FirstName
列,LastName
,DepartmentId
和MasterLookup
表,字段为Id
,{{1} }。我还有一个Category, Value
表,它具有以下值。 (请注意,此表包含多个类别的值。即Department和MaritalStatus。)
Department
我想列出Employee表中的所有员工,他们的部门按升序排序,如下所示
1 Department Human Resources
2 Department Accounting
3 Department Operations
4 MaritalStatus Married
5 MaritalStatus Single
这是我到目前为止所做的:
FirstName.. Accounting
FirstName... Accounting
FirstName... Human Resources
FirstName... Operations
可以使用动态查询完成吗?
答案 0 :(得分:0)
我想列出Employee表中的所有员工,他们的部门按升序排序
按DepartmentName
列排序:
SELECT Emp.FirstName, Dept.DepartmentName
FROM Employee Emp
LEFT OUTER JOIN Department Dept ON Emp.DepartmentId = Dept.DepartmentId
ORDER BY Dept.DepartmentName ASC;