Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
POSTGRESQL_CLOSEST_VALUE
CREATE TABLE TX (CRITERION INT, VARIABILE INT); INSERT INTO TX VALUES (1,2), (2,4),(3,2),(4,7), (5,6); SELECT * FROM TX; SELECT CRITERION, MIN_DELTA FROM ( SELECT TX.CRITERION , MIN(ABS(B.TX2_VAR - TX.VARIABILE)) OVER (PARTITION BY TX.CRITERION) AS MIN_DELTA , RANK() OVER (PARTITION BY TX.CRITERION ORDER BY ABS(B.TX2_VAR - TX.VARIABILE) ) AS MIN_RANK FROM TX LEFT JOIN LATERAL (SELECT TX2.CRITERION AS TX2_CRIT, TX2.VARIABILE AS TX2_VAR FROM TX TX2 WHERE TX2.CRITERION < TX.CRITERION) B ON TRUE ) C WHERE MIN_RANK=1 ORDER BY CRITERION ; DROP TABLE TX;
run
|
edit
|
history
|
help
0
Select the latest id from last week from each different contact without repeating barcodes .....
PostgreSQL: Inner Join
Laidata Practice
Correlated subquery in SELECT clause, and rewritten for Netezza
SQL2_CLASS
Weekly Average Starting on Different Days
On conflict
1
jsonb handle
1