| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

03-24-11, 07:05
|
|
Registered User
|
|
Join Date: Mar 2011
Location: Sydney, Australia
Posts: 58
|
|
|
current year
|
|
How do I express the current year in the following calculation? I've readed masses of notes but can't find this answer.
I have to find horses over 15 years old. horse_born is the column containing the horse's year of birth:
SELECT horse_id, horse_name
FROM horse
WHERE "expression for current year" - horse_born >15
|
|

03-24-11, 08:39
|
|
vaguely human
|
|
Join Date: Jun 2007
Location: London
Posts: 2,519
|
|
After extensive searching I found the following page.
The year function looked particularly relevant.
|
|

03-24-11, 09:28
|
|
Registered User
|
|
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 623
|
|
|
|
To add to Mike's suggestion try using curdate() or now() to get today's date or date/time.
|
|

03-24-11, 12:20
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
|
|
Quote:
Originally Posted by it-iss.com
... try using curdate() or now() to get today's date or date/time.
|
please, don't use those
use these instead -- CURRENT_DATE, CURRENT_TIMESTAMP
they are totally equivalent, ~and~ they will also work in other database systems, thus making your code portable and not dependent on proprietary mysql syntax

|
|

03-24-11, 12:22
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
|
|
Quote:
Originally Posted by melgra70
WHERE "expression for current year" - horse_born >15
|
don't do a calculation involving the column value, the database engine won't be able to optimize the query
instead, put the column value on one side of the comparison operator, and do the calculation on the other side --
WHERE horse_born < YEAR(CURRENT_DATE) - INTERVAL 15 YEAR

|
|

03-24-11, 12:42
|
|
vaguely human
|
|
Join Date: Jun 2007
Location: London
Posts: 2,519
|
|
I think I preferred it when we provided NZDF solutions to homework questions rather than high efficiency multi-platform solutions. It was also far more fun.
|
|

03-24-11, 16:16
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
|
|
Quote:
Originally Posted by mike_bike_kite
I think I preferred it when we provided NZDF solutions to homework questions
|
i believe that i did

|
|

03-24-11, 16:35
|
|
vaguely human
|
|
Join Date: Jun 2007
Location: London
Posts: 2,519
|
|
I obviously wasn't paying enough attention in class then
|
|

03-24-11, 16:39
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
|
|
so i guess this was a good nzdf then?

|
|

03-24-11, 17:24
|
|
vaguely human
|
|
Join Date: Jun 2007
Location: London
Posts: 2,519
|
|
oh definitely - keep up the good work 
|
|

03-24-11, 19:40
|
|
Registered User
|
|
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 623
|
|
nzdf - what does this mean? I googled it and found New Zealand Defense Force and New Zealand Drillers Federation - though I don't think either apply here 
|
|

03-24-11, 20:14
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
|
|
NZDF is a term which was first coined here in these very forums by, ahem, yours truly
it stands for Non-Zero Deviosity Factor, and refers to the practice of responding to certain requests for homework assistance with an answer that is devious to some extent
obviously, a student struggling with a homework problem, who makes a game attempt, and shows his work, and discusses what he's tried and what concepts he's having trouble with, is going to receive answers largely devoid of any deviosity
the idea is that the larger the deviosity, the more likely it is that the student will get into trouble if he hands in the answer he obtained here
and it's particularly effective if the answer actually happens to work correctly, but in a way so devious that the student doesn't twig onto the ruse but the teacher surely will
can you see what the NZDF was in this thread?
|
|

03-25-11, 03:31
|
|
Registered User
|
|
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 623
|
|
LOL - of course as a student once I was more intent on getting the solution working, less about performance and cross platform compatibility. I like it - NZDF!! I will have to use this too!!
|
|

03-25-11, 05:00
|
|
vaguely human
|
|
Join Date: Jun 2007
Location: London
Posts: 2,519
|
|
I wonder whether we should have a monthly award for the best response. The only danger with NZDF is that some future associate might look for your name on the web and come up with the code and just think WTF?
|
|

03-25-11, 12:51
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
|
|
Quote:
Originally Posted by mike_bike_kite
I wonder whether we should have a monthly award for the best response.
|
pat would win it in a cakewalk every month
i've never seen anybody come even close to his level of deviosity

|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|