all groups > sql server notification services > april 2005 >
You're in the

sql server notification services

group:

I need help with SELECT statement


I need help with SELECT statement Vanessa Lee
4/14/2005 6:18:57 PM
sql server notification services:
Hi, Could you help me modify the SELECT statement below that would
accomplish my final goal.

SELECT col1, col2 FROM table1 WHERE col3 < @V

In col1 rows have many duplicates
col2 has unique values
col3 can have 5 possible values: 5, 10, 15, 20, 25
Variable @V can be equal to 5 or 10 or 15 or 20 or 25

The goal is to:

Return row values from col1 without duplicates, and return corresponding
values from col2 (both col1 and col2 in one row) "WHERE" col3 always has
maximum value from all possible values but is <= @V

Thank you.
Vanessa

Re: I need help with SELECT statement Joe Webb
4/14/2005 10:14:52 PM
Vanessa -

An interesting goal. I'm sure someone in the
microsoft.public.sqlserver.programming would likely be willing to help.
This group is for SQL Server Notification Services.


Joe Webb
SQL Server MVP

~~~
Get up to speed quickly with SQLNS
http://www.amazon.com/exec/obidos/tg/detail/-/0972688811



[quoted text, click to view]
RE: I need help with SELECT statement Balaji Ramachandran
4/19/2005 4:44:02 AM
Hi,

I took the authors table in pubs database.

col1 = state
col2 = au_id
col3 = zip


[quoted text, click to view]

Here you have to take a decision. As col1 can have duplicates, for a single
value for col1 will return more than one values for col2.

So you can take min, max, average values of this rows.

Here goes the query....

select state, min(au_id), max(zip)
from authors
where zip < 94609
group by state

Hope this helps.

Regards,
R.Balaji

[quoted text, click to view]
AddThis Social Bookmark Button