将Teradata SQL转换为BigQuery SQL
如何将SQL转换为BigQuery?
SELECT
MAX(var1)*2 as name1,
name1+11 as name2
FROM table
在BigQuery中,如果我在上面的行中声明NAME1,则无法使用NAME1。
我知道我可以做到这一点,但是当SQL很大时,需要更改很多,可能还有其他更简单的选项。
SELECT
MAX(var1)*2 as name1,
MAX(var1)*2+11 as name2
FROM table
How do I convert following sql to bigquery?
SELECT
MAX(var1)*2 as name1,
name1+11 as name2
FROM table
In bigquery I can't use name1 if I declare it in the line above.
I know i can do this, but when sql is big then a lot needs to be changed, there may be other simpler options.
SELECT
MAX(var1)*2 as name1,
MAX(var1)*2+11 as name2
FROM table
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能以这种方式重复使用BigQuery的别名,您将不得不重复完整的表达方式或子查询。假设以前的选项:
唯一的其他选项是子查询:
但是从性能的角度来看,子查询版本在第一个版本上具有额外的成本。除非您确实需要重复大量代码,否则您可能应该选择重复别名表达式。
You can't reuse the alias in this way on BigQuery, you will have to repeat the full expression or subquery. Assuming the former option:
The only other option would be to subquery:
But from a performance point of view, there is an added cost which the subquery version has over the first version. You should probably go with repeating the alias expression unless you really would need to repeat a lot of code.