Teradata 默认列表
有一张表,其中包含我需要的金额和说明。但是,该表包含年份信息,但我想要月份信息。例如,表中显示了 2011 年肯塔基州的信息……仅此而已。对于加利福尼亚州,它显示大约 5 个不同的年份。但我需要每月重复一次。
因此,如果 2011 年肯塔基州总共有 12 个,那么我需要一个查询来显示一月、二月、五月的 12 个......
现在我用一个愚蠢的查询得到这个输出:
Kentucky 12 January
California 800 January
这可以通过按州分组轻松完成,数量和月份
我想确保无论数量是多少,每个州都有所有月份
Kentucky 12 January
Kentucky 12 February
Kentucky 12 May
California 800 January
California 800 February
California 800 May
您知道如何使用 Teradata SQL 执行此操作吗?
There is this one table which contains the amounts and states that I need. However, this table contains a year information but I want month. For example, in the table it shows information for Kentucky for 2011..and thats it. For California it shows about 5 different years. But I need it to repeat by month.
So if in 2011 Kentucky had 12 total, then I need a query that shows 12 for January, February, May....repeatedly
Right now I get this output with a dumb query I have:
Kentucky 12 January
California 800 January
This is done easily by grouping by State, Quantity and Month
I want to make sure that no matter what the Quantity is, each State has ALL months
Kentucky 12 January
Kentucky 12 February
Kentucky 12 May
California 800 January
California 800 February
California 800 May
Any idea on how to do this with Teradata SQL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
整个查询看起来像这样:
all_months 括号之间的内容取决于“所有月份”的含义。
如果您的意思是出现在 state_quantities 中的所有月份,无论哪个州(因此,如果肯塔基州为 1 月,加利福尼亚州为 2 月,佛罗里达州为 5 月,那么您只能得到这三个月),您可以使用如下内容:
如果您想要所有 12 个月份月,您将连接到包含所有 12 个月的表。如果没有,您可以使用 sys_calendar.calendar (下面的语法可能会关闭):
The overall query would look something like this:
What goes between the brackets for all_months depends on what you mean by "all months".
If you mean all months that appear in state_quantities irrespective of state (so if you have Kentucky with January, California with February and Florida with May, you'd only get those three months) you could use something like this:
If you want all 12 months, you would join to a table containing all 12 months. In the absence of that, you could use sys_calendar.calendar (syntax below might be off):