SQL选择按查询排序的列
我试过了,用谷歌搜索了我能想到的一切,但我找不到答案,因为我有一个简单的数据库 技术员SQL选择按查询排序的列,sql,oracle,Sql,Oracle,我试过了,用谷歌搜索了我能想到的一切,但我找不到答案,因为我有一个简单的数据库 技术员 +------------------+------------+------+-----+ | Field | Type | Null | Key | +------------------+------------+------+-----+ | employe id | number(4) | NO | PRI | | name
+------------------+------------+------+-----+
| Field | Type | Null | Key |
+------------------+------------+------+-----+
| employe id | number(4) | NO | PRI |
| name | char(11) | NO | |
| salary | int(11) | NO | |
+------------------+------------+------+-----+
维护
+------------------+------------+------+---------+
| Field | Type | Null | Key |
+------------------+------------+------+---------+
| employe id | number(4) | NO | foreign |
| IP | char(11) | NO | foreign |
| maintenance_date | int(11) | NO | |
+------------------+------------+------+---------+
个人电脑
我需要的是显示每个进行了维护的technicien
的姓名、id和工资,按所进行维护的总数排序。选择technicien.name、technicien.employeId、technicien.salary
来自technicien
内部连接维护
关于维护.employeId=technicien.employeId
内连接pc
ON maintenance.IP=pc.IP
按计数排序的订单(维护。维护\u日期)
您需要的是根据表technicien的列进行分组,并按维护任务计数排序:
提示:加入
<代码>分组依据
。显示您迄今为止尝试过的查询。
+------------------+------------+------+---------+
| Field | Type | Null | Key |
+------------------+------------+------+---------+
| value | number(4) | NO | foreign |
| IP | char(11) | NO | PRI |
| price | int(11) | NO | |
+------------------+------------+------+---------+
select t.*, count(0) cnt_maintenance
from technicien t
inner join maintenance m on ( t.employee_id = m.employee_id )
inner join pc p on ( p.value = m.IP )
group by t.employee_id, t.name, t.salary
order by count(0);