Google BigQuery CASE功能 [英] Google BigQuery CASE function

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

问题描述

我试图运行一个查询,像这里所回答的一样,
SQL选择多个总和?

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

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

 message :无法识别的功能CASE。 

如果我尝试一个更简单的方法(从一个sql教程),

 选择案例1当1当'1'时2当'2'其他'更多'结束; 

然后我得到

 message:搜索的案例表达不支持:1.8  -  1.65。 

我将在黑暗中进行狂野刺杀,并假设SQL CASE函数是整体只是不支持BigQuery,但真的希望我错了,因为它会根据我想要运行的报表查询产生巨大的差异。 解决方案

更新:BigQuery支持CASE:

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

'one'


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".

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;

I then get

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

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 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天全站免登陆