我有两张microsoft Access Database
这样的桌子
1.HR_人事
+-----+----------+----------------------+
| ID | NIP | Name |
+----------------+----------------------+
| 1 | 200 | Teguh |
| 2 | 201 | Supomo |
| 3 | 203 | DHINI ADHITYAS M |
| 4 | 204 | Dhani Amanda |
+-----+----------+----------------------+
TA_Record_Info
+---------+-----------------------+
| Per_Code| Date_Time |
+---------+-----------------------+
| 3 | 2013-02-20 07:45:57 |
| 2 | 2013-02-20 07:46:13 |
| 1 | 2013-02-20 08:48:07 |
| 1 | 2013-02-20 15:53:40 |
| 3 | 2013-02-20 16:01:02 |
| 2 | 2013-02-21 07:31:57 |
| 3 | 2013-02-21 07:39:29 |
| 3 | 2013-02-21 15:51:47 |
| 2 | 2013-02-21 16:11:21 |
| 2 | 2013-02-22 07:47:45 |
| 1 | 2013-02-22 07:53:31 |
| 3 | 2013-02-22 16:01:43 |
| 2 | 2013-02-22 16:11:19 |
| 1 | 2013-02-22 16:15:26 |
+---------+-----------------------+
预期结果编辑
+-------+-----------------+-------------+-------------+-------------+
| NIP | Nama | adate | InTime | OutTime |
+-------+-----------------+-------------+-------------+-------------+
| 201 | Teguh | 2013-02-20 | 08:48:07 | 15:53:40 |
| 202 | Supomo | 2013-02-20 | 07:46:13 | - |
| 203 | DHINI ADHITYAS M| 2013-02-20 | 07:45:57 | 16:01:02 |
| 204 | Dhani Amanda | 2013-02-20 | - | - |
| 201 | Teguh | 2013-02-21 | - | - |
| 202 | Supomo | 2013-02-21 | 07:31:57 | 16:11:21 |
| 203 | DHINI ADHITYAS M| 2012-08-21 | 07:39:29 | 15:51:47 |
| 204 | Dhani Amanda | 2013-02-21 | - | - |
| 201 | Teguh | 2012-08-22 | 07:53:31 | 16:15:26 |
| 202 | Supomo | 2012-08-22 | 07:47:45 | 16:11:19 |
| 203 | DHINI ADHITYAS M| 2012-08-22 | - | 16:01:43 |
| 204 | Dhani Amanda | 2013-02-22 | - | - |
+-------+-----------------+-------------+-------------+-------------+
我试过这个查询编辑
SELECT p.NIP AS NIP,
p.Name AS Nama,
Format (a.Date_Time, 'yyyy-mm-dd') as adate,
IIF((Min(a.Date_Time) <> Max(a.Date_Time)),
Format (Min(a.Date_Time), 'hh:mm:ss'),
IIF( Format (Min(a.Date_Time), 'hh:mm:ss') < '12:00:00',
Format (Min(a.Date_Time), 'hh:mm:ss'),
'-'
)
)as InTime,
IIF((Max(a.Date_Time) <> Min(a.Date_Time)),
Format (Max(a.Date_Time), 'hh:mm:ss'),
IIF( Format (Max(a.Date_Time), 'hh:mm:ss') > '12:00:00',
Format (Max(a.Date_Time), 'hh:mm:ss'),
'-'
)
)as OutTime
FROM HR_Personnel AS p
LEFT JOIN TA_Record_Info a
ON p.ID = a.Per_Code
GROUP BY p.Per_Code,
p.Per_Name,
Format (a.Date_Time, 'yyyy-mm-dd')
Order BY Format (a.Date_Time, 'yyyy-mm-dd'),
Right(p.Per_Code,2),
p.Per_Name
但结果显示如下编辑
+-------+-----------------+-------------+-------------+-------------+
| NIP | Nama | adate | InTime | OutTime |
+-------+-----------------+-------------+-------------+-------------+
| 204 | Dhani Amanda | | | - |
| 201 | Teguh | 2013-02-20 | 08:48:07 | 15:53:40 |
| 202 | Supomo | 2013-02-20 | 07:46:13 | - |
| 203 | DHINI ADHITYAS M| 2013-02-20 | 07:45:57 | 16:01:02 |
| 202 | Supomo | 2013-02-21 | 07:31:57 | 16:11:21 |
| 203 | DHINI ADHITYAS M| 2012-08-21 | 07:39:29 | 15:51:47 |
| 201 | Teguh | 2012-08-22 | 07:53:31 | 16:15:26 |
| 202 | Supomo | 2012-08-22 | 07:47:45 | 16:11:19 |
| 203 | DHINI ADHITYAS M| 2012-08-22 | - | 16:01:43 |
+-------+-----------------+-------------+-------------+-------------+
我认为我的查询结果是由我离开加入使用引起的
ON p.ID=a.Per_Code
编辑 所以 teguh 不在 2013-02-21 日期不显示。表格仅显示了在 2013-02-22 - 2013-02-22 日期期间缺席的 Dhani Amanda。
我只是想显示员工室友表不存在于所有特定日期或标记为 Intime 和 OutTime 为空的日期
最后我必须从我的查询中改变什么?我希望你能帮助我。谢谢。
更新
我错了。我在表结果和预期结果表之间颠倒写了。然后结果表作为不存在Teguh
的员工不存在。我改变了我的解释。然后在查询中
SELECT p.NIP AS NIP,
p.Name AS Nama,
改变
SELECT p.NIP AS NIP,
p.Name AS Nama,
我已经用EDIT
标签编辑了我的问题。谢谢。