반응형
https://www.hackerrank.com/certificates/iframe/8e57e6090694
SELECT sender,
Min(dt) AS sequence_start,
Max(dt) AS sequence_end,
Count(*) AS transactions_count,
Sum(amount) AS transactions_sum
FROM transactions
WHERE sender = recipient
AND dt BETWEEN Dateadd(hour, -1, Min(dt)) AND Max(dt)
GROUP BY sender,
sequence_start,
sequence_end
HAVING Count(*) >= 2
AND Sum(amount) >= 150
ORDER BY sender ASC,
sequence_start ASC,
sequence_end ASC;
SELECT sender,
Min(dt) AS sequence_start,
Max(dt) AS sequence_end,
Count(*) AS transactions_count,
Sum(amount) AS transactions_sum
FROM transactions
WHERE sender = recipient
AND dt BETWEEN Dateadd(hour, -1, Min(dt)) AND Max(dt)
GROUP BY sender,
sequence_start,
sequence_end
HAVING Count(*) >= 2
AND Sum(amount) >= 150
ORDER BY sender ASC,
sequence_start ASC,
sequence_end ASC;
반응형
'Data Analysis > SQL' 카테고리의 다른 글
[SQL] 23.Inverted Index 인버티드 인덱스란 무엇인가 ? 그리고 왜 Elastic Search 에서 인버티드 인덱스를 사용하는가 ? (0) | 2023.02.12 |
---|---|
[SQL]. 22 SQL에서 Trend 제거하기 (0) | 2023.01.31 |
19.[SQL] Json 형식의 데이터를 Select 하는 방법 (MySQL, PostgreSQL) (0) | 2023.01.22 |
18. [SQL] SQL에서 ACID는 무엇일까 ? (0) | 2023.01.05 |
17. [SQL] 정규화(Normalization) (0) | 2023.01.04 |
댓글