我更多的是sql的初学者,但希望得到一些帮助,哪个语句将是最好的用于我的查询。所以我有一个有测试数据的应用程序,因为分数可能是90或85.6。值在不同的列中-前者在int.value中,后者在double.value中。我需要将这两列合并成一个列,用于"test_score“。这是我当前的查询,数据转到一个名为“App_test_outcome”的表中:
SELECT event_date, timestamp_micros(event_timestamp) as Timestamp, user_pseudo_id, geo.country, geo.region, geo.city, geo.sub_continent,
(select value.string_value from unnest (event_params) where key = "test_passed") as Test_outcome,
(select value.string_value from unnest (event_params) where key = "test_category") as Test_outcome_category,
(select value.double_value from unnest (event_params) where key = "test_score") as Test_outcome_score,
FROM `Appname.analytics_number.events_*`
WHERE
_TABLE_SUFFIX BETWEEN '20200201' AND '20201130' AND
event_name = "test_completed"我是否需要进行另一个查询,然后与该表中已有的上述查询合并,或者有没有办法运行一个查询并将两列合并为一个。如果可能的话,我更喜欢后一种选择。
当我试图向int.value追加一个带有double.value的查询时,我确实收到了一条错误消息,但是出现了一条错误消息"invalid schema: Field Test_outcome_score已将类型从浮点型改为整型“。这让我觉得我无论如何都不能合并这两列。
任何帮助都是最好的,
非常感谢,
发布于 2020-12-02 19:57:43
也许IFNULL的CAST会有所帮助:
(select IFNULL(value.double_value, CAST(value.int_value AS FLOAT64)) from unnest (event_params) where key = "test_score") as Test_outcome_scorehttps://stackoverflow.com/questions/65107538
复制相似问题