0

嗨,我是 mysql 数据库的新手,任何人都可以解决我的问题吗?我有三个这样的表

select * from device;
Vehiclegroup  vehicleName  deviceid  accountid  
------------  -----------  --------  -----------
sms           cargo        test1      sysadmin   
sms           cargo1       test2     sysadmin   
sms           cargo3       test3     sysadmin   
select * from Account;
accountid  password  deviceid  
---------  --------  ----------
sysadmin   pass      test3     
sysadmin   pass      test2     
sysadmin   pass      test1     
And finally 

mysql> select * from eventdata;
+-----------+-------+----------+----------+
| accountid | speed | date     | deviceid |
+-----------+-------+----------+----------+
| sysadmin  | 45    | 12/10/13 | test3    |
| sysadmin  | 45    | 10/10/13 | test3    |
| sysadmin  | 45    | 10/10/13 | test2    |
| sysadmin  | 45    | 11/10/13 | test2    |
| sysadmin  | 45    | 14/10/13 | test2    |
| sysadmin  | 45    | 17/10/13 | test2    |
| sysadmin  | 45    | 17/10/13 | test1    |
+-----------+-------+----------+----------+
7 rows in set (0.00 sec) 

这里我需要如下所示的输出表

vehiclegroup vehiclename deviceid date
sms              cargo1  test1  17/10/13
sms              cargo2  test2  17/10/13
sms              cargo3  test3  12/10/13

即,我需要每个设备在最后一个工作日期的数据,任何人都可以为此提供帮助

4

1 回答 1

0

像这样的东西?

SELECT d.Vehiclegroup, d.vehicleName, e.deviceid, e.date
FROM eventdata e
INNER JOIN device d ON e.deviceid = d.deviceid
GROUP BY e.deviceid

每个 deviceid 将为您提供一条记录。车辆组、车辆名称和日期是从列表中任意选择的。如果您想要最新的,您应该使用子查询或修饰符,例如( MAX(e.date) 作为日期)

于 2013-11-05T12:40:46.967 回答