How to choose which row to use

  • Hello,

    I have a database of students' grades, however some are numeric and some are alpha. Depending on the grade type will determine which average and which standard deviation to use but I'm not sure how to go about this. The CASE statement doesn't work and I can't use a where clause because a student could have either or in any of the other classes. If anyone could point me in the right direction. Thanks!

    SECTION AVERAGE GradeType StandardDeviation

    789 80 Numeric 6.5874

    256 2.48 AlPha 0.1269

  • giszzmo (5/18/2015)


    Hello,

    I have a database of students' grades, however some are numeric and some are alpha. Depending on the grade type will determine which average and which standard deviation to use but I'm not sure how to go about this. The CASE statement doesn't work and I can't use a where clause because a student could have either or in any of the other classes. If anyone could point me in the right direction. Thanks!

    SECTION AVERAGE GradeType StandardDeviation

    789 80 Numeric 6.5874

    256 2.48 AlPha 0.1269

    It's not totally clear what you are trying to achieve.

    Please provide DDL, sample data and desired results as described in the first link in my signature. Someone will help you if you take the time to do this.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • If grade isnumeric then grade type is numeric so use that row of values, else it must be alpha

  • giszzmo (5/18/2015)


    If grade isnumeric then grade type is numeric so use that row of values, else it must be alpha

    And what does this mean?

  • Every time I see a question that involves students or grades, I think "homework!"


    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

  • Awww how sad for you. You must think nobody works in education. How narrow minded of you.

  • giszzmo (5/19/2015)


    Awww how sad for you. You must think nobody works in education. How narrow minded of you.

    And being condescending is NOT a good way to illicit help from people. I would think that somebody who indicates they work in education would be able to form a more complete question with details.

    The reason behind that thinking is because so many students come here looking for us to do their homework for them.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Let's please be polite.

    To giszzmo,

    It's not completely clear what you are trying. It is helpful if you post some DDL and inserts for the data like this:

    create table Grades

    ( SECTION int

    , AVERAGE numeric(8,2)

    , GradeType varchar(200)

    , StandardDeviation numeric(8,4)

    );

    go

    insert Grades select 789, 80, ,'Numeric', 6.5874

    union

    select 256, 2.48, 'AlPha', 0.1269

    That helps someone do a quick setup and experiment.

    However you mention a CASE not working. Can you post your code? and any issue/error? It helps us to understand what you are doing, and if you include the results you are looking for, we can help you understand the issue.

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply