【问题标题】:SQL in BigQuery data returning as nullBigQuery 数据中的 SQL 返回为空
【发布时间】:2021-12-03 00:54:34
【问题描述】:

问题: 在 BigQuery 中运行查询时,使用 SQL 命令

SELECT 
 usertype,
 CONCAT(start_station_name,'to',end_station_name) as route,
 COUNT(*) as num_trips,
 Round(AVG(Cast(tripduration as int64)/60),2) as duration
FROM `bigquery-public-data.new_york_citibike.citibike_trips`
 GROUP BY start_station_name, end_station_name, usertype
 ORDER BY num_trips DESC 
 LIMIT 10

我得到第一行数据为空和空,我不明白为什么?有人可以解释我做错了什么或为什么返回时数据不完整。是因为时间进入第二天还是之前和下午?

usertype    route   num_trips   duration
    to  5828994 
Customer    Central Park S & 6 AvetoCentral Park S & 6 Ave  46671   50.36
Customer    Grand Army Plaza & Central Park StoGrand Army Plaza & Central Park S    21039   58.02
Customer    Centre St & Chambers SttoCentre St & Chambers St    17543   34.75
Subscriber  W 21 St & 6 Aveto9 Ave & W 22 St    17260   5.23
Subscriber  W 21 St & 6 AvetoW 22 St & 10 Ave   14715   6.94
Subscriber  Pershing Square NorthtoW 33 St & 7 Ave  12559   8.4
Customer    Broadway & W 60 SttoBroadway & W 60 St  12528   52.09
Subscriber  W 22 St & 10 AvetoW 22 St & 8 Ave   11764   3.58
Subscriber  Pershing Square NorthtoE 24 St & Park Ave S 11737   7.03

【问题讨论】:

    标签: sql google-bigquery


    【解决方案1】:

    您在 SQL 中没有做错任何事情。这只是表包含错误/空白/空数据的情况。

    select count(*), sum(tripduration)
    from `bigquery-public-data.new_york_citibike.citibike_trips`
    where usertype = '' or start_station_name = '' or end_station_name = ''
    

    如果您想清理原始查询,只需添加 where usertype <> ''

    【讨论】:

    • 不会找到并突出显示NULL 条目。需要OR x IS NULLCOALESCE(x, '') = ''
    • @MatBailie 表示同意,但我引用的字段中实际上没有任何NULLs,它们都是'' 空字符串。
    • This is just a case where the table has bad/blank/null data.
    猜你喜欢
    • 2014-04-19
    • 2020-08-07
    • 2022-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多