[英]sql | need query to filter data
I have this dataset where i need to figure out, For which account there is both a -ve and a +ve amount for a given date through out the month.我有这个数据集,我需要弄清楚,对于哪个帐户,整个月的给定日期都有 -ve 和 +ve 金额。
also to display these accounts with respective amount and date还显示这些帐户的相应金额和日期
Date acct amt
x 123 -1.1
x 123 2.3
y 234 1.4
y 234 1.5
y 234 -4.3
z 345 8.2
z 345 1.3
your help is much appreciated.非常感谢您的帮助。
EDIT:编辑:
Select date, acct, amt
from table_name
where date between 'x' and 'z'
order by date, acct;
now i can see the data like i have shown above but i am not able to figure out what to use to move forward.现在我可以看到上面显示的数据,但我无法弄清楚使用什么来前进。
expected result (account with z date is gone as it had both +ve transactions):预期结果(z 日期的帐户已消失,因为它有两个 + 5 笔交易):
Date acct amt
x 123 -1.1
x 123 2.3
y 234 1.4
y 234 1.5
y 234 -4.3
You decide what you want to do with 0
你决定你想用
0
做什么
SELECT Table1.*
FROM Table1
JOIN
(
SELECT "Date", "acct"
FROM Table1
GROUP BY "Date", "acct"
HAVING
MIN("amt") < 0
AND MAX("amt") > 0
) T
ON Table1."Date" = T."Date"
AND Table1."acct" = T."acct"
OUTPUT输出
| Date | acct | amt |
|------|------|------|
| x | 123 | -1.1 |
| x | 123 | 2.3 |
| y | 234 | 1.4 |
| y | 234 | 1.5 |
| y | 234 | -4.3 |
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.