在访问数据库设计器中使用带有计数的多列
Using multiple columns with counts in access database designer
我试图在 Microsoft Access 查询中显示多个具有不同计数的列。它不允许我做某些普通查询可以做的事情 b/c 它有 sql 设计视图。
我想展示
多个单独的 etc 列及其计数。
注意:table 名称和属性已更改。
select (select count(*)as multiple from (select userId from dbo.Purchases
where userId is not null GRoup by userId having count(*)>1) x), (
select count(*)as single from (select userId from dbo.Purchases where
userId is not null GRoup by userId having count(*)=1) x );
如果我分别执行这些操作,我可以显示它,但我想将它们组合成一个查询和一行。这可能吗?
select count(*)as multiple from (select userId from dbo.Purchases
where userId is not null GRoup by userId having count(*)>1) x)
2个查询就很简单了:
第一个,另存为"Purchases Summary"
Select UserID, count(UserID) as Count from Purchases Group By UserID
在其上构建了第 2 个:
SELECT Sum(IIf([count]=1,1)) AS [Single], Sum(IIf([count]>1,1)) AS Multiple FROM [Purchases Summary]
我找不到将其组合成单个查询的巧妙方法。
我不知道我昨晚的问题是什么,但是单个查询是
SELECT Sum(IIf([count]=1,1)) AS [Single], Sum(IIf([count]>1,1)) AS Multiple
FROM (Select UserID, count(UserID) as Count from Purchases Group By UserID)
Don George 解决方案也可以。
我最终为每一列使用了一个表单和 VBA。我遇到的一个问题是我需要对唯一 ID 使用不同的调用,并且当有 sql 设计视图不受真正支持时。支持 distinctrow,但它不适用于我的查询。我最终像以前一样写了它,所以它不需要 distinct。
这是我用来覆盖访问表单内每个输入的 VBA。 currentDb 需要正确连接到数据库才能正常工作。
selectStatement = "SELECT Count(* ) FROM (SELECT userID FROM dbo_Purchases WHERE userID is not null GROUP BY userID HAVING count(*)>1) AS x;"
rs = CurrentDb.OpenRecordset(selectStatement).Fields(0).Value
[Text30].Value = rs
我试图在 Microsoft Access 查询中显示多个具有不同计数的列。它不允许我做某些普通查询可以做的事情 b/c 它有 sql 设计视图。 我想展示 多个单独的 etc 列及其计数。
注意:table 名称和属性已更改。
select (select count(*)as multiple from (select userId from dbo.Purchases
where userId is not null GRoup by userId having count(*)>1) x), (
select count(*)as single from (select userId from dbo.Purchases where
userId is not null GRoup by userId having count(*)=1) x );
如果我分别执行这些操作,我可以显示它,但我想将它们组合成一个查询和一行。这可能吗?
select count(*)as multiple from (select userId from dbo.Purchases
where userId is not null GRoup by userId having count(*)>1) x)
2个查询就很简单了:
第一个,另存为"Purchases Summary"
Select UserID, count(UserID) as Count from Purchases Group By UserID
在其上构建了第 2 个:
SELECT Sum(IIf([count]=1,1)) AS [Single], Sum(IIf([count]>1,1)) AS Multiple FROM [Purchases Summary]
我找不到将其组合成单个查询的巧妙方法。
我不知道我昨晚的问题是什么,但是单个查询是
SELECT Sum(IIf([count]=1,1)) AS [Single], Sum(IIf([count]>1,1)) AS Multiple
FROM (Select UserID, count(UserID) as Count from Purchases Group By UserID)
Don George 解决方案也可以。 我最终为每一列使用了一个表单和 VBA。我遇到的一个问题是我需要对唯一 ID 使用不同的调用,并且当有 sql 设计视图不受真正支持时。支持 distinctrow,但它不适用于我的查询。我最终像以前一样写了它,所以它不需要 distinct。 这是我用来覆盖访问表单内每个输入的 VBA。 currentDb 需要正确连接到数据库才能正常工作。
selectStatement = "SELECT Count(* ) FROM (SELECT userID FROM dbo_Purchases WHERE userID is not null GROUP BY userID HAVING count(*)>1) AS x;"
rs = CurrentDb.OpenRecordset(selectStatement).Fields(0).Value
[Text30].Value = rs