在BigQuery中结合使用CAST和SELECT吗?

时间:2019-02-03 14:27:05

标签: sql select casting google-bigquery create-table

我想创建一个table_2variable不同的table_1值的CREATE TABLE `table_2` AS SELECT DISTINCT(CAST(variable AS NUMERIC)) FROM `table_1`; ,然后将它们从STRING预先转换为NUMERIC。

我的猜测是:

//index.pug

extends layout

block campground 
  - var campgrounds = '#{camps}'
    .row
      each campground in campgrounds
        div.col-md-3.col-sm-6
          div
            img(src=`${campground.image}` class='img-thumbnail')
            a(href=`/campgrounds/${campground._id}`)
              h4.caption.text-center #{campground.name}





//app.js

app.get('/campgrounds', async (req, res) => {
    try {
        const camps = await Camp.find();
        res.render('index', { camps: camps });
    } catch (ex) {
        res.status(500).send('internal error');
    }
});

但这不起作用。 有什么建议吗?

2 个答案:

答案 0 :(得分:1)

DISTINCT不需要括号。您还需要命名输出列。试试这个:

CREATE TABLE `table_2` AS
SELECT DISTINCT CAST(variable AS NUMERIC) AS variable
FROM `table_1`;

答案 1 :(得分:0)

尝试一下:

CREATE TABLE `table_2` AS
  SELECT CAST(variable AS NUMERIC)
  FROM `table_1`
  GROUP BY variable;