我试图在微软访问查询中显示具有不同计数的多个列。它不允许我做某些事情,普通的查询可以b / c它有sql设计视图。 我想要展示 多个单个等等列及其计数。
注意:表名和属性已更改。
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)
答案 0 :(得分:1)
使用2个查询非常简单:
第一个,保存为“购买摘要”
Select UserID, count(UserID) as Count from Purchases Group By UserID
建立第二个:
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)
答案 1 :(得分:0)
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