我有两张这样的桌子
1.HR_人事
+-----+---------------+--------+
| ID | NIP | Name |
+---------------------+--------+
| 1 | 050803075200 | Teguh |
| 2 | 050803075201 | Supomo |
+-----+---------------+--------+
2.TA_Record_Info
+-----+-----+---------+-----------------------+
| NIP | NIP | Nama | Date_Time |
+-----+-----+---------+-----------------------+
| 2 | 2 | Supomo | 2013-02-20 07:45:57 |
| 2 | 2 | Supomo | 2013-02-20 17:24:13 |
| 1 | 1 | Supomo | 2013-02-20 18:18:07 |
| 2 | 2 | Supomo | 2013-02-21 07:53:40 |
| 2 | 2 | Teguh | 2013-02-21 20:31:02 |
| 1 | 1 | Teguh | 2013-02-21 17:31:57 |
+-----+-----+---------+-----------------------+
Date_Time
是字符串格式。
然后我想让它像这张桌子一样:
+----------------+---------+-------------+-------------+-------------+
| NIP | Nama | Date | In | Out |
+----------------+---------+-------------+-------------+-------------+
| 050803075200 | Teguh | 2013-02-21 | | 18:18:07 |
| 050803075200 | Teguh | 2013-02-20 | | 20:31:02 |
| 050803075201 | Supomo | 2013-02-20 | 07:45:57 | 17:24:13 |
| 050803075201 | Supomo | 2013-02-21 | 07:53:40 | 17:31:57 |
+----------------+---------+-------------+-------------+-------------+
我根据我之前的问题DateTime String to Date, In Time 和 Out Time的回答尝试了 MySQL Query 。成功了 这是查询代码:
SELECT p.Per_Code as NIP,
p.Per_Name as Nama,
DATE_FORMAT(a.Date_Time, '%Y-%m-%d') as date,
Case Min(a.Date_Time)
When Max(a.Date_Time)
Then ''
Else DATE_FORMAT(a.Date_Time, '%H:%i:%s')
End as InTime,
DATE_FORMAT(max(a.Date_Time), '%H:%i:%s') as OutTime
FROM HR_Personnel as p
RIGHT JOIN TA_Record_Info a
ON p.ID=a.Per_ID
Group By NIP,
Nama,
DATE_FORMAT(Date_Time, '%Y-%m-%d')
你可以在这里看到 MYSQL 查询测试
然后我在 ms Access 中尝试过,但仍然无法正常工作。这是查询代码:
SELECT p.Per_Code AS NIP,
p.Per_Name AS Nama,
Format (a.Date_Time, "yyyy-mm-dd") as date,
IIF(
(Min(a.Date_Time) = Max(a.Date_Time)) ,
'',
Format (a.Date_Time, "hh/mm/ss")
)as InTime,
Format (Max(a.Date_Time), "hh/mm/ss") AS OutTime
FROM HR_Personnel AS p
RIGHT JOIN TA_Record_Info a
ON p.ID=a.Per_ID
GROUP BY p.Per_Code,
p.Per_Name,
Format (a.Date_Time, "yyyy-mm-dd")
我在我的 PDO:Querry 中尝试过,但仍然显示错误消息:
致命错误:调用成员函数 fetch()
我不知道如何在 ms-access 中进行测试。我只知道PHP and MySql
。我使用ms-access
数据库是因为我的信息系统与只有 ms-access 数据库的指纹连接。
我必须做什么来解决这个问题?