我有两张这样的表
1.HR_Personnel
+-----+---------------+--------+
| 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 and Out Time的答案尝试了MySQL查询。这是成功的。这是查询代码:
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查询测试in Here
然后我在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数据库
我该怎么做才能解决这个问题?
答案 0 :(得分:1)
问题已经解决了。查询必须如下:
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 (Min(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")
错误在于第7行。 以前的查询是这样的:
格式(a.Date_Time,“hh / mm / ss”)
然后改变如下:
格式(Min(a.Date_Time),“hh / mm / ss”)
我认为错误的发生是因为ms-access无法识别a.Date_Time
。
最后,感谢HansUp继续回答我的问题。干杯:D