Skip to content

Commit

Permalink
variables
Browse files Browse the repository at this point in the history
  • Loading branch information
rakshit087 committed Jul 31, 2023
1 parent c4dab03 commit 350bc3f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions mind-map-book/src/sql/14_variables.md
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
# Variables

QUERY TO FIND MEDIAN

```sql
SET @N := 0;
SELECT COUNT(*) FROM STATION INTO @TOTAL;
SELECT
ROUND(AVG(A.LAT_N), 4)
FROM (SELECT @N := @N +1 AS ROW_ID, LAT_N FROM STATION ORDER BY LAT_N) A
WHERE
CASE WHEN MOD(@TOTAL, 2) = 0
THEN A.ROW_ID IN (@TOTAL/2, (@TOTAL/2+1))
ELSE A.ROW_ID = (@TOTAL+1)/2
END
;
```

0 comments on commit 350bc3f

Please sign in to comment.