Home Forums SQL Server 2008 SQL Server 2008 - General Calculating Median, Max, Min, Lower Quartile and Upper Quartile for a Boxchart? RE: Calculating Median, Max, Min, Lower Quartile and Upper Quartile for a Boxchart?

  • DataAnalyst011 (1/17/2013)


    The output should be something like below with values filled in for x:

    Year Median Max Min LowerQ UpperQ

    2010 x x x x x

    2011 x x x x x

    2012 x x x x x

    CREATE TABLE EStats

    (

    PersonIDVARCHAR(30)NOT NULL,

    GradeVARCHAR(25)NOT NULL,

    CourseDateDateNOT NULL

    )

    ;

    INSERT INTO EStats

    (

    PersonID, Grade, CourseDate

    )

    VALUES

    ('100', '91', '2010-03-01'),

    ('101', '96', '2010-03-01'),

    ('102', '88', '2010-03-01'),

    ('103', '92', '2010-03-01'),

    ('104', '81', '2010-03-01'),

    ('105', '85', '2010-03-01'),

    ('106', '91', '2010-03-01'),

    ('107', '89', '2010-03-01'),

    ('108', '99', '2010-03-01'),

    ('109', '88', '2010-03-01'),

    ('110', '81', '2011-03-02'),

    ('111', '77', '2011-03-02'),

    ('112', '88', '2011-03-02'),

    ('113', '76', '2011-03-02'),

    ('114', '69', '2011-03-02'),

    ('115', '70', '2011-03-02'),

    ('116', '75', '2011-03-02'),

    ('117', '88', '2011-03-02'),

    ('118', '76', '2011-03-02'),

    ('119', '95', '2012-03-01'),

    ('120', '96', '2012-03-01'),

    ('121', '90', '2012-03-01'),

    ('122', '80', '2012-03-01'),

    ('123', '85', '2012-03-01'),

    ('124', '94', '2012-03-01'),

    ('125', '89', '2012-03-01'),

    ('126', '97', '2012-03-01'),

    ('127', '94', '2012-03-01'),

    ('128', '72', '2012-03-01'),

    ('129', '88', '2012-03-01'),

    ('130', '91', '2012-03-01')

    I would love to try and help but help me out please. Can you fill in the expected results with exactly the real results that you expect to see from the given sample data?

    I initially did some fumbling around but I couldn't quite 'ken exactly what you were after so I kind of punted with the suggestion I made earlier.

    If I have a clear target, I'm usually pretty good at hitting it.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St