SQL - MS ACCESS - 显示带有 0 的 NULL 值的单元格
我尝试在访问中编写查询。
我的目标是;
获得一天内完成了多少次手术的结果。
问题是;
结果给了我日期和做了多少次手术,但结果表上没有列出没有进行任何手术的天数。
我希望未手术的天数显示为 0。 但没有关于 2009 年 1 月 3 日进行 1 型手术的记录。我只想通过那一行;
类型 1------------30.01.2009------------0
是否可能或如何?
例如,
手术类型 ------------日期 ---------------- 金额
--------类型 1-------- ----------01.01.2009------------------20
----------类型 1--------- --------02.01.2009------------------30
--!!--!!-- 03.01.2009 未显示为 0 (没有出现在结果表中)--!!--!!--
----------类型 1-----------------02.01.2009-- ----------------10
我尝试使用ISNULL函数但没有得到结果。
*B is SURGERY TYPE
*T is DATES
SQL Code
SELECT T1.B, T1.T, Count(T1.T) AS Amount
FROM T1
GROUP BY T1.B, T1.T
HAVING (((T1.B) In (SELECT [B] FROM [T1] As Tmp GROUP BY [B] HAVING Count(*)>1))) ORDER BY T1.B;
I tried to write a query in access.
My aim is;
To get results of how many surgeries are done in one day.
Problem is;
Result are giving me dates and how many surgeries are done but days without any surgery are not listed on the result table.
I want days without surgery to be shown as 0.
But there is no record about SURGERY TYPE 1 ON 03.01.2009. I just want to pass that row like;
TYPE 1------------30.01.2009------------0
IS IT POSSIBLE or HOW ?
Eg,
SURGERY TYPES ------------DATES----------------AMOUNT
-------TYPE 1-----------------01.01.2009------------------20
-------TYPE 1-----------------02.01.2009------------------30
--!!--!!-- 03.01.2009 is not shown as 0 ( It didn't appear on the resulting table )--!!--!!--
-------TYPE 1-----------------02.01.2009------------------10
I've tried to use ISNULL function but couldn't get a result.
*B is SURGERY TYPE
*T is DATES
SQL Code
SELECT T1.B, T1.T, Count(T1.T) AS Amount
FROM T1
GROUP BY T1.B, T1.T
HAVING (((T1.B) In (SELECT [B] FROM [T1] As Tmp GROUP BY [B] HAVING Count(*)>1))) ORDER BY T1.B;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要一个外部联接。外连接将允许主表中的所有记录,并且仅允许外连接表中匹配的记录。这允许记录存在于计数为零的地方。
You need an outer join. An outer join will allow all records from the main table, and only those records from the outer-joined table that match. This allows records to exist where count is zero.