dbTalk Databases Forums  

complex SQL ?

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss complex SQL ? in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jazz
 
Posts: n/a

Default complex SQL ? - 12-12-2008 , 09:04 AM






SQL question

If I have a table like that

ID | ESTIMATED_VAL | REAL_VAL

xyz | 100 | 129
abc| 110 | 80

etc...

I want a query that returns all underestimated values, so:

if ESTIMATED_VAL < REAL_VAL return ID

Something like that. Do you know how to write the SQL query?

Many thanks

Reply With Quote
  #2  
Old   
Jazz
 
Posts: n/a

Default Re: complex SQL ? - 12-12-2008 , 10:02 AM






I figured it out, sorry, it is not very complex at all,

SELECT * FROM table t where t.est < t.real;

or also using HAVING clause somehow...


Reply With Quote
  #3  
Old   
Jazz
 
Posts: n/a

Default Re: complex SQL ? - 12-12-2008 , 10:02 AM



I figured it out, sorry, it is not very complex at all,

SELECT * FROM table t where t.est < t.real;

or also using HAVING clause somehow...


Reply With Quote
  #4  
Old   
Jazz
 
Posts: n/a

Default Re: complex SQL ? - 12-12-2008 , 10:02 AM



I figured it out, sorry, it is not very complex at all,

SELECT * FROM table t where t.est < t.real;

or also using HAVING clause somehow...


Reply With Quote
  #5  
Old   
Jazz
 
Posts: n/a

Default Re: complex SQL ? - 12-12-2008 , 10:02 AM



I figured it out, sorry, it is not very complex at all,

SELECT * FROM table t where t.est < t.real;

or also using HAVING clause somehow...


Reply With Quote
  #6  
Old   
DA Morgan
 
Posts: n/a

Default Re: complex SQL ? - 12-12-2008 , 01:55 PM



Jazz wrote:
Quote:
I figured it out, sorry, it is not very complex at all,

SELECT * FROM table t where t.est < t.real;

or also using HAVING clause somehow...
Glad you solved it ... but a couple of pointers.

1. HAVING clause is filtering on groups created by GROUP BY
2. ID is a reserved word
3. REAL is a reserved word

SELECT COUNT(*)
FROM v$reserved_words
WHERE keyword = '<your_word_here>';

Is a valuable query to learn.
--
Daniel A. Morgan
Oracle Ace Director & Instructor
University of Washington
damorgan@x.washington.edu (replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org


Reply With Quote
  #7  
Old   
DA Morgan
 
Posts: n/a

Default Re: complex SQL ? - 12-12-2008 , 01:55 PM



Jazz wrote:
Quote:
I figured it out, sorry, it is not very complex at all,

SELECT * FROM table t where t.est < t.real;

or also using HAVING clause somehow...
Glad you solved it ... but a couple of pointers.

1. HAVING clause is filtering on groups created by GROUP BY
2. ID is a reserved word
3. REAL is a reserved word

SELECT COUNT(*)
FROM v$reserved_words
WHERE keyword = '<your_word_here>';

Is a valuable query to learn.
--
Daniel A. Morgan
Oracle Ace Director & Instructor
University of Washington
damorgan@x.washington.edu (replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org


Reply With Quote
  #8  
Old   
DA Morgan
 
Posts: n/a

Default Re: complex SQL ? - 12-12-2008 , 01:55 PM



Jazz wrote:
Quote:
I figured it out, sorry, it is not very complex at all,

SELECT * FROM table t where t.est < t.real;

or also using HAVING clause somehow...
Glad you solved it ... but a couple of pointers.

1. HAVING clause is filtering on groups created by GROUP BY
2. ID is a reserved word
3. REAL is a reserved word

SELECT COUNT(*)
FROM v$reserved_words
WHERE keyword = '<your_word_here>';

Is a valuable query to learn.
--
Daniel A. Morgan
Oracle Ace Director & Instructor
University of Washington
damorgan@x.washington.edu (replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org


Reply With Quote
  #9  
Old   
DA Morgan
 
Posts: n/a

Default Re: complex SQL ? - 12-12-2008 , 01:55 PM



Jazz wrote:
Quote:
I figured it out, sorry, it is not very complex at all,

SELECT * FROM table t where t.est < t.real;

or also using HAVING clause somehow...
Glad you solved it ... but a couple of pointers.

1. HAVING clause is filtering on groups created by GROUP BY
2. ID is a reserved word
3. REAL is a reserved word

SELECT COUNT(*)
FROM v$reserved_words
WHERE keyword = '<your_word_here>';

Is a valuable query to learn.
--
Daniel A. Morgan
Oracle Ace Director & Instructor
University of Washington
damorgan@x.washington.edu (replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org


Reply With Quote
  #10  
Old   
Paul Linehan
 
Posts: n/a

Default Re: complex SQL ? - 12-13-2008 , 01:29 PM





Jazz wrote:

Quote:
SQL question
If I have a table like that
ID | ESTIMATED_VAL | REAL_VAL

xyz | 100 | 129
abc| 110 | 80

etc...

I want a query that returns all underestimated values, so:

if ESTIMATED_VAL < REAL_VAL return ID

Something like that. Do you know how to write the SQL query?
SELECT ID FROM MyTableName (not supplied)
WHERE ESTIMATED_VAL < REAL_VAL

Unless I've missed something, this is quite easy.


Paul...


--



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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.