how to extract only mondays in 2007
Teradata Teradata Discussion Forums Teradata.com Discussion Forum
Visit Teradata.com
Home       Guidelines    Member List
Welcome Guest ( Login | Register )
        


This online forum is for user-to-user discussions of Teradata products, and is not an official customer support channel for Teradata. If you require direct assistance, please contact Teradata support.


how to extract only mondays in 2007 Expand / Collapse
Author
Message
Posted 3/1/2007 5:03:05 PM
Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: 4/22/2007 2:58:00 PM
Posts: 18, Visits: 1
Needs extract only mondays in 2007.

how can i achevie using Teradata SQL

Thanks
Chinna
Post #6756
Posted 3/2/2007 1:04:58 AM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 6/25/2008 12:53:07 PM
Posts: 118, Visits: 60
Chinna,

Your question is very vague.
Do you have a table which has a date column and do you want to extract Mondays from those values
or
in general from calendar view?

Yet I guess this select will help you achieve if you change it according to your needs.

The following SQL extracts all Mondays in the date range mentioned in the where clause.

select * from sys_calendar.calendar where day_of_week=2 and calendar_date between date -77 and date
order by 1;

Also check this URL when you have time.
http://www.teradataforum.com/attachments/a040409b.doc

Hope this serves your question.



Regards
Ramakrishna_Vedantam
Post #6765
Posted 3/5/2007 8:39:28 AM
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: 6/27/2008 7:19:28 AM
Posts: 42, Visits: 54
Do you think multi-posting is the best way to get an answer ?
Post #6786
Posted 8/1/2007 7:38:03 AM
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: 8/15/2008 8:48:08 AM
Posts: 29, Visits: 41
The syntax would be like this:

Sel*
from tablename
where Tablename_date_column IN(
select Calendar_Date from sys_calendar.calendar where day_of_week=2 and extract(year from calendar_date) = 2007 order by 1)
;

Remember that for Teradata, Sunday is the first day of the week.

Regards,


Andrew C. Livingston
Teradata Certified Professional and Trainer
Post #8422
Posted 10/18/2007 3:32:18 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 1/28/2008 8:40:36 AM
Posts: 5, Visits: 10
Hi Mr. Livingston,

I tried your query, and got an error that order by should not be used in the sub query. Can you give any other alternative.

Regards,
Ravi

Post #9289
Posted 10/18/2007 12:42:09 PM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 8/24/2008 2:47:14 PM
Posts: 425, Visits: 398
The "order by 1" clause is not required, he must have accidentally put it there ...... remove it and the query will work fine.
Post #9298
Posted 10/20/2007 9:45:51 AM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 8/28/2008 2:06:25 PM
Posts: 80, Visits: 89
Sub queries can not have order by clause.(I have read it too)

But can anyone give the reason for the same?


Regards,
Sakthi

Do your duty Dont expect the reward, God will give the benefit for you

Post #9315
Posted 10/20/2007 12:09:57 PM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 8/24/2008 2:47:14 PM
Posts: 425, Visits: 398
That's because it's pointless to have an order by clause in a subquery.

For example

if you write

SEL A FROM TAB1 WHERE A IN (SELECT B FROM TAB2 WHERE B IS NOT NULL)

your are saying you need all the "A"s from tab1 which is also there in tab2 (as column B).

now if you write it as

SEL A FROM TAB1 WHERE A IN (SELECT B FROM TAB2 WHERE B IS NOT NULL ORDER BY 1)

This does not make any difference to the query's output or semantic meaning, because in set theory { a, b, c, d } = { b, c, d, a } = { c, d, a, b } etc ..... ie the order of elements doesn't matter... the IN sql operator is a set operator, so the order of elements in the subquery output is irrelevant for the operator. so db doesn't want to do an extra effort of doing an ordering, which doesn't alter the semantics of the query. This is the same reasoning why the order by operator is not allowed at other places in subqueries, these are all set operations in one form or the other.
Post #9316
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: