I am a beginner in SQL language (neither Oracle or Access) and I am trying to convert this Oracle SQL to MS Access SQL code but it failed with the following error:
Syntax error(missing operator) in query expression
Any idea?
Oracle SQL
SQL> select
2 o.item,
3 o.qty ord_qty,
4 i.loc,
5 i.purch,
6 i.qty loc_qty,
7 sum(i.qty) over (
8 partition by i.item
9 order by i.purch, i.loc
10 rows between unbounded preceding and current row
11 ) sum_qty
12 from orderline o
13 join inventory i
14 on i.item = o.item
15 where o.ordno = :pick_order
16 order by
17 o.item,
18 i.purch,
19 i.loc;
MS Access SQL
SELECT o.item, o.qty AS ord_qty, i.Loc, i.purch, i.qty AS loc_qty, sum(i.qty) over (partition by i.item rows between unbounded preceding and current row) AS sum_qty
FROM orderline AS o INNER JOIN inventory AS i ON o.item = i.item
WHERE (((o.ordno)=1))
ORDER BY o.item, i.purch, i.Loc;
You can probably do what you want using a correlated subquery. My best guess is:
SELECT o.item, o.qty AS ord_qty, i.Loc, i.purch, i.qty AS loc_qty,
(SELECT SUM(i2.qty)
FROM orderline o2 INNER JOIN
inventory as i2
ON o2.item = i2.item
WHERE o2.ordno = 0.orderno AND
i2.item = i.item AND
(i2.purch < i.purch or
i2.purch = i.purch and i2.loc = i.loc
)
) as sum_qty
FROM orderline AS o INNER JOIN
inventory AS i
ON o.item = i.item
WHERE o.ordno = 1
ORDER BY o.item, i.purch, i.Loc;
正如其他一些人提到的,MS Access 不支持窗口函数
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.