无论如何,当显示结果时,是否有连接选择查询列?

时间:2017-10-06 09:10:29

标签: sql google-bigquery

例如我有一个查询:

select item_name, day, month, year from some_table;

但是我希望结果表是2列,而不是4,就像那样:

  

[商品名称] [日期(dd.mm.YYYY)]

我们可以这样做吗?

我使用Google的Biq Query标准SQL。

3 个答案:

答案 0 :(得分:3)

以下是BigQuery Standard SQL

  
#standardSQL
SELECT item_name, DATE(year, month, day) AS date
FROM `yourTable`

您可以使用以下虚拟数据进行测试/播放

#standardSQL
WITH `yourTable` AS (
  SELECT 'abc' AS item_name, 5 AS day, 10 AS month, 2017 AS year UNION ALL
  SELECT 'xyz', 1, 9, 2017
)
SELECT item_name, DATE(year, month, day) AS date
FROM `yourTable`

答案 1 :(得分:2)

使用此查询

select item_name, CONCAT(cast(day as STRING)) ,'.' ,cast(month as STRING), '.',cast(year as STRING)) as Date

答案 2 :(得分:1)

您可以使用 CONCAT

<强>查询

select item_name, concat(day, '.', month, '.', year) as date
from some_table;

如果列是整数类型,则必须将其强制转换为字符串。

select item_name,
concat(cast(day as string), '.', cast(month as string), '.', cast(year as string)) as date
from some_table;