晕大家。
我在MySQL中构建了一个代码,并希望通过Microsoft查询在excel工作表中使用它。 代码的一部分(第二个JOIN)的目的是揭示客户的第一笔交易发生的日期。为此,我使用了“row_number”方法。问题是,当我将代码复制到我的Microsoft查询中时,看起来excel完全忽略了我使用过的“row_number”函数。代码如下:
SELECT
e.debtor_id, d.name, f.created as First_capture, cb.CARD, cb.BANKING
FROM
capital.cached_entry e
JOIN
capital.debtor d ON e.debtor_id = d.id
JOIN
(SELECT
@row_number:=IF(@debtorid=t.debtor_id,@row_number+1,1) AS RowNumber,
t.debtor_id,
t.created,
te.fromState,
@debtorid:=t.debtor_id
FROM capital.transaction t
JOIN capital.transaction_event te ON t.id=te.auth_entry_id
where toState='captured'
order by t.debtor_id, t.created) f ON f.debtor_id=e.debtor_id
JOIN (SELECT
debtor_id,
SUM(CASE when type='CARD_PAYMENT' then 1 else 0 end) as CARD,
SUM(CASE when type='BANKING_PAYMENT' then 1 else 0 end) as BANKING
FROM
capital.cached_entry e
JOIN
capital.debtor d ON e.debtor_id = d.id
WHERE
e.cacheType = 'DEBTOR'
GROUP by debtor_id) cb on e.debtor_id=cb.debtor_id
WHERE
e.cacheType = 'DEBTOR'
AND e.created <= '2016-10-25' and Rownumber=1
GROUP BY e.debtor_id
HAVING SUM(e.amount) != 0;
我做错了什么? Microsoft查询中是否存在“row_number”或者是其他名称的函数?