“Finden Sie den Median in SQL” Code-Antworten

Finden Sie den Median in SQL

# FOR TABLES WITH ODD NUMBER OF ROWS

# For column1 in table1 with 'n' number of rows. Where 'n' is an odd number.
# 1. Change all column1 and table1 to your column and table name.
# 2. Calculate (n/2)+0.5, where n=number of rows, and set it as LIMIT for t1.

SELECT *
FROM (SELECT column1
      FROM table1
      ORDER BY column1
      LIMIT (n/2)+0.5) AS t1
ORDER BY column1 DESC
LIMIT 1;
Kwams

Wie finde ich Median einer Spalte SQL

SET @rowindex := -1;
 
SELECT
   AVG(g.grade)
FROM
   (SELECT @rowindex:=@rowindex + 1 AS rowindex,
           grades.grade AS grade
    FROM grades
    ORDER BY grades.grade) AS g
WHERE
g.rowindex IN (FLOOR(@rowindex / 2) , CEIL(@rowindex / 2));
Disgusted Dingo

Ähnliche Antworten wie “Finden Sie den Median in SQL”

Fragen ähnlich wie “Finden Sie den Median in SQL”

Weitere verwandte Antworten zu “Finden Sie den Median in SQL” auf Sql

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen