-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4dab03
commit 350bc3f
Showing
1 changed file
with
16 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
; | ||
``` |