sql server 2008 - SQL Query Help Part 2 - Add filter to joined tables and get max value from filter -


I asked questions on SO, however, I wish to extend it. I would like to get the maximum value of the 'reading' column only in the place where the 'state' value is an example of 'XX'.

So if I join two tables, then how do I compare the line results with the maximum (reading) value. E.g.

  SELECT s *, G1. * As a grade of pair from school, G1 on G. 1. ID-school = s.id WHERE s.state = 'SA' // How do I get this result set from the line with the maximum reading ( 

The details of the table are:

  Table 1 = School column: ID (PK), state (nvchar (100)), school name table 2 = grade column: ID (PK), ID_school (FK), year, reading, writing ...  

I want to use a normal table expression I will think in RE: Institution with schools (ID, State, School Name) AS (SELECT id, state, schoolname, WHERE state = 'XX' from schools) = G.ID_Schools in schools Select the school from the institutions as the grade of. G. Reading = Maximum (G. Readings)

The good thing about this is that it makes these schools a pseudo table that wraps all the arguments about the state's filtering, by which You can write your remaining questions without thinking about it.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -