aggregated functions and group by postgresql



  • We need to remove the median sample and sample size. the median is the value of which порядковому номеру = размер/2 rounded down to the lower side,

    i.e. this example should be 33 in place 7

    We need to sign 33/15.

    Here's my code, which doesn't work like this the use of aggregate functions requires a group by

    CREATE TABLE random(ID INT primary key , Value INT unique )  
    INSERT INTO random 
    values 
    (1,1),
    (2,3),
    (3,7),
    (4,10),
    (5,16),
    (6,17),
    (7,33),
    (8,21),
    (9,27),
    (10,41),
    (11,25),
    (12,13),
    (13,23),
    (14,29),
    (15,9)
    

    Select cast count() as tatal, value from random
    where id = cast (count(
    )/2 as int)

    Is it possible to rewrite something with help? group by ? free with as и limit



  • Try using the sub-conquests:

    SELECT
        (select count(*) from random) as total_count,
        value 
    

    FROM
    random
    WHERE
    id = (select cast (count()/2 as int) from random)

    UPD.

    Then instead id row number

    SELECT tcount, value FROM
    (SELECT
    ROW_NUMBER() over (ORDER BY id) as rnum,
    COUNT() over () as tcount,
    value
    FROM random) sq
    WHERE
    sq.rnum = (select cast (count(*)/2 as int) from random)




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2