这是我的查询,一直返回错误00906. 00000 - "缺少左括号" - 它表示它应该在from table b) b
行。不知道我在这里做错了什么帮助非常感谢。我正在尝试选择地址相同且状态不同的记录。
select ADD.ID, ADD.Address, ADD.Unit, ADD.Status FROM
(select b.*, min(ADD.status) OVER (partition by ADD.Address) as minstatus,
max(ADD.status) OVER (partition by ADD.Address) as maxstatus
from ADD b) b
where minstatus <> maxstatus
order by ADD.Address;
理想情况下,这会返回这些记录:
ID | Address | Unit | Status
1 |555 Smith Rd | Apt A | Success
2 |555 Smith Rd | Apt B | Success
3 |555 Smith Rd | Apt C | Success
4 |555 Smith Rd | Apt D | Failure
答案 0 :(得分:1)
将add
视为表名,正确的查询应为 -
SELECT c.id,
c.address,
c.unit,
c.status
FROM (SELECT b.*,
MIN(b.status) over(PARTITION BY b.address) AS minstatus,
MAX(b.status) over(PARTITION BY b.address) AS maxstatus
FROM add b) c
WHERE c.minstatus <> c.maxstatus
ORDER BY c.address;