Unix Technical Forum

SQL query required

This is a discussion on SQL query required within the Pgsql Performance forums, part of the PostgreSQL category; --> Hi, Here's an interesting query problem i have. Would greatly appreciate some help on this 1. Table: Student Cols: ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Performance

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 11:36 AM
dey.indranil@gmail.com
 
Posts: n/a
Default SQL query required

Hi,
Here's an interesting query problem i have. Would greatly appreciate
some help on this 1.

Table: Student
Cols: Fname(not null), Lname, Marks(not null)
No primary key.

I want the highest marks of a given frist name whose last name is not
null.

Sample:

Fname Lname Marks
-------------------------------
Tom Evans 10
Tom Evans 20
Tom 30
Harry Potter 80
Harry Potter 30
Harry Potter 20
Dick 30
------------------------------

Expected RS:

Fname Marks
----------------------------
Tom 20
Harry 80

Thanks in advance,
Indranil.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-19-2008, 11:36 AM
David Shane Holden
 
Posts: n/a
Default Re: SQL query required

dey.indranil@gmail.com wrote:
> Hi,
> Here's an interesting query problem i have. Would greatly appreciate
> some help on this 1.
>
> Table: Student
> Cols: Fname(not null), Lname, Marks(not null)
> No primary key.
>
> I want the highest marks of a given frist name whose last name is not
> null.
>
> Sample:
>
> Fname Lname Marks
> -------------------------------
> Tom Evans 10
> Tom Evans 20
> Tom 30
> Harry Potter 80
> Harry Potter 30
> Harry Potter 20
> Dick 30
> ------------------------------
>
> Expected RS:
>
> Fname Marks
> ----------------------------
> Tom 20
> Harry 80
>
> Thanks in advance,
> Indranil.
>


select fname, max(marks) from student where lname is not null group by
fname;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:49 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com