块引用
我和小组有一些混淆。按组合排序。我有一个包含多个列的Employee表。喜欢:Name, Id, Sal, ServiceType,Center
等。
我想让所有员工按照ServiceType
和Name
分配给定Center
现在这就是我尝试过的,当然它不起作用。
SELECT servicetype, name, CentreCode
FROM Employee
GROUP BY CentreCode ORDER BY servicetype, name
请帮我解决正确的问题
table data
=========
servicetype name CentreCode
1 lee 1
1 john 1
12 smith 2
12 brown 3
output
======
servicetype name CentreCode
1 john 1
1 lee 1
12 brown 3
12 smith 2
答案 0 :(得分:0)
你可以这样做:
SELECT servicetype, name, CentreCode
FROM Employee
ORDER BY CentreCode,servicetype, name
或针对特定中心:
SELECT servicetype, name, CentreCode
FROM Employee
WHERE CentreCode='some code'
ORDER BY servicetype, name
答案 1 :(得分:0)
尝试使用:
SELECT servicetype, name, CentreCode
FROM Employee
GROUP BY servicetype, name, CentreCode
ORDER BY servicetype, name
在Select子句中使用的字段在Goup by中必须相同,其他你可以使用这样的agregation函数:
SELECT count(servicetype), count(name), CentreCode
FROM Employee
GROUP BY CentreCode
ORDER BY CentreCode