我有一个记录列表:
is_checkout() &&
并希望获得每条记录显示多少次的结果,例如:
IF
我的编码就像:
UniqueID
110000
110000
110001
110002
110002
110002
这将为我提供“函数的无效参数”的结果,并且如果我删除order1之类的参数,该代码将起作用
UniqueID times
110000 1
110000 2
110001 1
110002 1
110002 2
110002 3
如果我将代码更改为count(B.Num1)并创建一个新查询,该代码将为我提供“输入参数值A.Order1”的结果,如:
SELECT m.UniqueID,
(SELECT Count(*)
From [Query1] AS m2
Where m2.UniqueID =m.UniqueID And m2.Order1 <= m.Order1) AS COL2b
FROM [Query1] AS m;
我确定Order1字段或访问权限存在问题。我该如何解决?
供参考,Num1是1的列表。 Query1看起来像
SELECT m.UniqueID,
(SELECT Count(*)
From [Query1] AS m2
Where m2.UniqueID =m.UniqueID) AS COL2b
FROM [Query1] AS m;
,查询1的访问sql代码为:
SELECT A.UniqueID, (Select Count(B.Num1)
From [Query1] As B
Where B.UniqueID = A.UniqueID AND B.Order1 <= A.Order1) AS COL2b
FROM [Query1] AS A
ORDER BY A.UniqueID;
答案 0 :(得分:0)
为什么不做类似的事情:
SELECT a.UniqueId, count(a.uniqueId)
FROM Table a
GROUP BY a.uniqueId
答案 1 :(得分:0)
尝试分析功能。像这样:
select UniqueID
, row_number() over(partition by UniqueID order by UniqueID) times
from query1
答案 2 :(得分:0)
您最好的选择(除了更改数据库外)是:
SELECT m.UniqueID,
(SELECT Count(*)
FROM [Query1] AS m2
WHERE m2.UniqueID = m.UniqueID AND
m2.inflow <= m.inflow
) AS COL2b
FROM [Query1] AS m;
这假设inflow
对于每个uniqueid
是唯一的。
如果这不起作用,则可以将数据复制到具有自动编号列的新表中。您可以使用自动编号列代替inflow
。