Google BigQuery CASE 函数 [英] Google BigQuery CASE function

查看:27
本文介绍了Google BigQuery CASE 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试像这里回答的那样运行查询,SQL 选择多个总和?

I'm trying to run a query like what's answered here, SQL Selecting multiple sums?

SELECT  SUM(CASE WHEN order_date >= '01/01/09' THEN quantity ELSE 0 END) AS items_sold_since_date,
    SUM(quantity) AS items_sold_total,
    product_ID
FROM    Sales
GROUP BY product_ID

但是如果我尝试这样做,我会收到错误消息

But if I try that, I get the error message

"message": "Unrecognized function CASE".

如果我尝试更简单的(来自 sql 教程),

If I try a much more simple (from an sql tutorial),

SELECT CASE 1 WHEN 1 THEN 'one' WHEN 2 THEN 'two' ELSE 'more' END;

然后我得到

"message": "searched case expression not supported at: 1.8 - 1.65".

我将在黑暗中大胆尝试,并假设 BigQuery 总体上不支持 SQL CASE 函数,但我真的希望我错了,因为根据报告它会产生巨大的差异我想运行的查询.

I'm going to take a wild stab in the dark and assume that the SQL CASE function is overall just not supported on BigQuery, but really hope that I'm wrong because it makes a huge bit of difference based on the report queries I want to run.

推荐答案

2013 更新:BigQuery 支持 CASE:

2013 update: BigQuery supports CASE:

SELECT CASE WHEN x=1 THEN 'one' WHEN x=2 THEN 'two' ELSE 'more' END 
FROM (SELECT 1 AS x) 

'one'

这篇关于Google BigQuery CASE 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆