我有一个查询(在VB字符串中连接):
SELECT a.table_no as tbl, COUNT(b.table_no) as total_call_count,
AVG(TimeValue(c.service_time) * 86400) as total_time
FROM table_button_link a, button_log b, service_time_log c
WHERE b.table_no = c.table_no
AND Format(b.transaction_datetime,""DD/MM/yyyy"") = '" & Date.Now.ToString("d") & "' "
AND b.type <> 2 AND b.table_no = a.table_no AND c.table_no = a.table_no
GROUP BY a.table_no
我想从表tbl_no
中计算button_log
,但它会像这样返回:
|tbl_no | total_call_count | total_time |
| 1 | 4661 | 7.2134 |
| 2 | 5 | 3 |
| 3 | 576 | 9.33333 |
我想要的输出是这样的:
|tbl_no | total_call_count | total_time |
| 1 | 5 | 7.2134 |
| 2 | 1 | 3 |
| 3 | 3 | 9.33333 |
button_log
看起来像这样:
| ID | table_no | type | transaction_datetime |
| 1 | 1 | 1 | 28/07/2017 10:41:34 AM |
| 1 | 1 | 2 | 28/07/2017 10:42:22 AM |
| 2 | 1 | 1 | 28/07/2017 10:42:25 AM |
| 3 | 2 | 1 | 24/07/2017 10:41:47 AM |
table_button_link
是这样的:
| ID | table_no | button_no |
| 1 | 1 | 1 |
| 2 | 2 | 2 |
service_time_log
就像:
| ID | table_no | service_time | transaction_date |
| 1 | 1 | 00:00:04 | 28/07/2017 10:42:22 AM |
| 1 | 2 | 00:00:05 | 28/07/2017 10:50:43 AM |
我认为它统计所有记录。我尝试使用COUNT(DISTINT b.table_no)
,但我猜MS Access无法做到这一点。我将如何实现这一目标?请帮忙。感谢。