简体   繁体   English

选择星期几是今天的星期几

[英]Select where day of the week is today's day of the week

I am using Teradata and working on a SQL statement. 我正在使用Teradata并正在处理SQL语句。 I have a table where an attribute is "day_of_week". 我有一个属性为“ day_of_week”的表。 Sunday is 1, Monday is 2 etc. 星期日是1,星期一是2,依此类推。

I would like to select only the rows where day_of_week is the same as today. 我只想选择day_of_week与今天相同的行。 For ex, today is a Thursday (day 5) so I would like to select where day_of_week =5. 例如,今天是星期四(第5天),所以我想选择day_of_week = 5。 Tomorrow is Friday, I will want to select where day = 6. 明天是星期五,我要选择日期= 6。

I know how to compute the day of the week corresponding to today : select sc.day_of_week from sys_calendar.calendar sc where sc.calendar_date = current_date 我知道如何计算与今天相对应的星期几:从sys_calendar.calendar sc中选择sc.day_of_week,其中sc.calendar_date = current_date

But I cannot use such a statement in the where clause of another select statement. 但是我不能在另一个select语句的where子句中使用这样的语句。

How would you go about solving my problem ? 您将如何解决我的问题?

What is you TD release? 您的TD版本是什么? Since 13.10 there's a day_of_week function (which has been renamed to td_day_of_week in TD14): 从13.10开始,有day_of_week函数(在TD14中已重命名为td_day_of_week):

WHERE day_of_week = td_day_of_week(current_date);

You can use such a statement in the where clause of another query, using a subquery: 您可以使用子查询在另一个查询的where子句中使用这样的语句:

where day_of_week = (select sc.day_of_week
                     from sys_calendar.calendar sc
                     where sc.calendar_date = current_date
                    )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM