BigQuery语法错误

时间:2014-12-22 17:51:43

标签: mysql google-bigquery

我在BigQuery中遇到此错误: 错误:语法错误:2:1期待:查询结束但得到:“CASE”

我正在使用的查询是:

SELECT DISTINCT 

 CASE 
   WHEN
       t1.x<=t2.x 
   THEN 
       t1.x 
   ELSE
       t2.x 
 END id1, 

 CASE 
   WHEN
       t1.x<=t2.x 
   THEN 
       t2.x 
   ELSE 
       t1.x 
 END id2 

 FROM test1 t1 
 CROSS JOIN test1 t2 
 WHERE NOT t1.x = t2.x

适用于mysql但不适用于BigQuery。

1 个答案:

答案 0 :(得分:6)

我不认为Bigquery支持SELECT DISTINCT。相反,请使用子查询和group by

SELECT id1, id2
FROM (SELECT (CASE WHEN t1.x <= t2.x THEN t1.x ELSE t2.x END) as id1, 
             (CASE WHEN t1.x <= t2.x THEN t2.x ELSE t1.x END) as id2 
      FROM test1 t1 CROSS JOIN
           test1 t2 
      WHERE NOT t1.x = t2.x
     ) t
GROUP BY id1, id2;