G
Guest
I need to write two seperate statements. One returns the max value from a
table and the other returns the 2nd highest value. Any help?
table and the other returns the 2nd highest value. Any help?
magicdds said:I have a similar issue. I need to select the highest 5 test scores in a list
of test scores. However, some of the test scores may be the same for two or
more students. How do I get the list of the top 5 test scores like this:
95
91
91
86
84
tina said:try
SELECT TOP 5 TableName.ScoreField
FROM TableName
ORDER BY TableName.ScoreField DESC;
replace "TableName" and "ScoreField" with the correct names of the table and
the field.
note that "The TOP predicate does not choose between equal values. In the
preceding example [of TOP 25 grade point averages], if the twenty-fifth and
twenty-sixth highest grade point averages are the same, the query will
return 26 records."
hth
magicdds said:I have a similar issue. I need to select the highest 5 test scores in a list
of test scores. However, some of the test scores may be the same for two or
more students. How do I get the list of the top 5 test scores like this:
95
91
91
86
84
Please let me know at (e-mail address removed)
Thanks
Nero said:hello... i have a similar query, however i need to find the max value from
60%of the total entries...please help
tina said:try
SELECT TOP 5 TableName.ScoreField
FROM TableName
ORDER BY TableName.ScoreField DESC;
replace "TableName" and "ScoreField" with the correct names of the table
and
the field.
note that "The TOP predicate does not choose between equal values. In the
preceding example [of TOP 25 grade point averages], if the twenty-fifth
and
twenty-sixth highest grade point averages are the same, the query will
return 26 records."
hth
magicdds said:I have a similar issue. I need to select the highest 5 test scores in a list
of test scores. However, some of the test scores may be the same for
two or
more students. How do I get the list of the top 5 test scores like
this:
95
91
91
86
84
Please let me know at (e-mail address removed)
Thanks
:
Why two separate statements?
First Query.
Select Max(Something) as Maximum
FROM YourTable
Second Query.
SELECT Max(Something) as 2ndMaximum
FROM YourTable
WHERE Something <
(SELECT Max(Something)
FROM YourTable)
Paul wrote:
I need to write two seperate statements. One returns the max value from a
table and the other returns the 2nd highest value. Any help?
John Spencer said:Generically, that could look like the following.
SELECT Max(SomeField) as MaxValue
FROM (SELECT Top 60 Percent *
FROM SOMETABLE
ORDER BY SomeOtherField Desc) as TOP60
Or you might be able to use a subquery on the primary key of the table
SELECT Max(SomeField) as MaxValue
FROM SomeTable
WHERE SomeTable.PK IN
(SELECT Top 60 Percent PK
FROM SomeTable
ORDER BY SomeOtherField, YetAnotherField, PK)
Nero said:hello... i have a similar query, however i need to find the max value from
60%of the total entries...please help
tina said:try
SELECT TOP 5 TableName.ScoreField
FROM TableName
ORDER BY TableName.ScoreField DESC;
replace "TableName" and "ScoreField" with the correct names of the table
and
the field.
note that "The TOP predicate does not choose between equal values. In the
preceding example [of TOP 25 grade point averages], if the twenty-fifth
and
twenty-sixth highest grade point averages are the same, the query will
return 26 records."
hth
I have a similar issue. I need to select the highest 5 test scores in a
list
of test scores. However, some of the test scores may be the same for
two
or
more students. How do I get the list of the top 5 test scores like
this:
95
91
91
86
84
Please let me know at (e-mail address removed)
Thanks
:
Why two separate statements?
First Query.
Select Max(Something) as Maximum
FROM YourTable
Second Query.
SELECT Max(Something) as 2ndMaximum
FROM YourTable
WHERE Something <
(SELECT Max(Something)
FROM YourTable)
Paul wrote:
I need to write two seperate statements. One returns the max value
from a
table and the other returns the 2nd highest value. Any help?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.