RE: someone double-check me on this sql

From: Taylor, Chris David <ChrisDavid.Taylor_at_ingrambarge.com>
Date: Fri, 29 Jun 2012 06:03:22 -0500
Message-ID: <C5533BD628A9524496D63801704AE56D75B2BA032B_at_SPOBMEXC14.adprod.directory>



Fergal,
Thanks - worked perfect. I'll remember that NOT () syntax for next time, instead of using double operators.

Chris Taylor

"Quality is never an accident; it is always the result of intelligent effort."
-- John Ruskin (English Writer 1819-1900)

Any views and/or opinions expressed herein are my own and do not necessarily reflect the views of Ingram Industries, its affiliates, its subsidiaries or its employees.

From: Fergal Taheny [mailto:ftaheny_at_gmail.com] Sent: Friday, June 29, 2012 12:58 AM
To: Taylor, Chris David
Subject: RE: someone double-check me on this sql

Hi Chris,

The query is returning the correct result. If you want to exclude may 2012 then the filter is NOT ( month = 5 and year = 2012 )

Regards,
Fergal
On 29 Jun 2012 03:42, "Taylor, Chris David" <ChrisDavid.Taylor_at_ingrambarge.com<mailto:ChrisDavid.Taylor_at_ingrambarge.com>> wrote: Oracle 10.2.0.4

Well, this gives me the right results but I don't understand why...

(change the AND to an OR)

select
tm.month, tm.year, count(*)
 from img.ton_miles tm
where (tm.month != 5 OR tm.year != 2012) group by tm.month, tm.year
order by 1,2

Chris Taylor

"Quality is never an accident; it is always the result of intelligent effort."
-- John Ruskin (English Writer 1819-1900)

Any views and/or opinions expressed herein are my own and do not necessarily reflect the views of Ingram Industries, its affiliates, its subsidiaries or its employees.

-----Original Message-----
From: oracle-l-bounce_at_freelists.org<mailto:oracle-l-bounce_at_freelists.org> [mailto:oracle-l-bounce_at_freelists.org<mailto:oracle-l-bounce_at_freelists.org>] On Behalf Of Taylor, Chris David Sent: Thursday, June 28, 2012 9:35 PM
To: 'oracle-l_at_freelists.org<mailto:oracle-l_at_freelists.org>' Subject: someone double-check me on this sql

I'm a bit fuzzy at the moment due to pain meds after a minor surgery so I'm hoping someone can spot my error (if I have an error)

Table has months, years and 'x' number of rows for each

The table has Years 2011 and 2012
In 2011, it has months 1-12
And in 2012 it has months 1-5

I run this:
Select month, year, count(*) -- month, and year are actual column names From some_table Where (month != 5 and year != 2012) Group by month, year /

The data set I get is Months 6-12 for 2011 *ONLY*

Shouldn't that query *ONLY* exclude MONTH=5 and YEAR 12 together? (instead of ALL 2012 and ALL 5s?)

Chris Taylor

"Quality is never an accident; it is always the result of intelligent effort."
-- John Ruskin (English Writer 1819-1900)

Any views and/or opinions expressed herein are my own and do not necessarily reflect the views of Ingram Industries, its affiliates, its subsidiaries or its employees.

--
http://www.freelists.org/webpage/oracle-l




--
http://www.freelists.org/webpage/oracle-l


--
http://www.freelists.org/webpage/oracle-l
Received on Fri Jun 29 2012 - 06:03:22 CDT

Original text of this message