Re: What's the correct select

From: Damjan S. Vujnovic <damjan_at_NOSPAMgaleb.etf.bg.ac.yu>
Date: Sat, 23 Nov 2002 08:41:09 +0100
Message-ID: <arnba4$eis$1_at_news.etf.bg.ac.yu>


> Here is a table marks:
>
> std_id number(4)
> std_name varchar2(30)
> subj1 number(3)
> subj2 number(3)
>
> select statment:
>
> select std_id, subj1+subj2 Total_Marks from marks
> where subj1 > avg(subj1) and subj2 > avg(subj2)
> order by std_id
>
> The statment returns an error at where clause, so what's the correct where
> clause

One of many possible solutions is:

SELECT std_id, subj1 + subj2 Total_Marks FROM marks
WHERE subj1 > (

    SELECT AVG(subj1)
    FROM marks) AND
    subj2 > (
    SELECT AVG(subj2)
    FROM marks);

Btw, it's a good practice to post the version of Oracle you're running as well as error message you're getting. And check out your manual about agregate functions...

Regards,
Damjan S. Vujnovic

University of Belgrade
School of Electrical Engineering
Department for Computer Engineering and Informatics Belgrade, Yugoslavia

http://galeb.etf.bg.ac.yu/~damjan Received on Sat Nov 23 2002 - 08:41:09 CET

Original text of this message