legacy-sql

Count number of events before and after a particular event in SQL?

可紊 提交于 2020-01-15 09:26:28
问题 I have a table containing date and events. There is event named 'A'. I want to find out how many events occurred before and after event 'A' in Sql Bigquery. for Example, User Date Events 123 2018-02-13 D 123 2018-02-12 B 123 2018-02-10 C 123 2018-02-11 A 123 2018-02-01 X The answer would be something like this. User Event Before After 123 A 2 2 I have tried many queries but its not working. Any Idea, how to solve this problem? 回答1: below is for BigQuery Standard SQL #standardSQL WITH `project

Count number of events before and after a particular event in SQL?

徘徊边缘 提交于 2020-01-15 09:23:06
问题 I have a table containing date and events. There is event named 'A'. I want to find out how many events occurred before and after event 'A' in Sql Bigquery. for Example, User Date Events 123 2018-02-13 D 123 2018-02-12 B 123 2018-02-10 C 123 2018-02-11 A 123 2018-02-01 X The answer would be something like this. User Event Before After 123 A 2 2 I have tried many queries but its not working. Any Idea, how to solve this problem? 回答1: below is for BigQuery Standard SQL #standardSQL WITH `project

Count number of events before and after a event “A” till another event “A” is encountered in Big query?

☆樱花仙子☆ 提交于 2020-01-14 03:55:14
问题 I have a table containing date and events and users. There is event named 'A'. I want to find out how many time a particular event occurred before and after event 'A' in SQL Bigquery. The event A might appear multiple times. But it should count events only till it encounters another event A in both before and after condition. for Example, User Date Events 123 2018-02-14 X.Y.A 123 2018-02-12 X.Y.B 134 2018-02-10 Y.Z.A 123 2018-02-11 A 123 2018-02-01 X.Y.Z 134 2018-02-05 X.Y.B 134 2018-02-04 A

Input calculates to invalid time: 24:00:00 in big query

為{幸葍}努か 提交于 2019-12-11 08:11:28
问题 I am running a query to bring time in 24 hr format but when i run query and it calculates time over 23:59:59, instead of going over and changing time to 00:00:00 it gives me error saying Input calculates to invalid time: 24:00:00. FORMAT_TIME('%T', TIME(DIV(sc.timestart, 60), MOD(sc.timestart, 60), 0)) AS TimeFrom, FORMAT_TIME('%k', TIME(DIV(sc.timestart + sc.timeduration, 60), MOD(sc.timestart + sc.timeduration, 60), 0)) AS TimeTo Error Input calculates to invalid time: 24:00:00 Row ClassID

BigQuery: error in SPLIT() returns

馋奶兔 提交于 2019-12-11 05:57:25
问题 I have a table TabA in BigQuery which has a column ColA and the column ColA has the following structure 1038627|21514184 and the table TabA has more than a million records. I used this to split into multiple columns SELECT ColA,FIRST(SPLIT(ColA, '/')) part1, NTH(2, SPLIT(ColA, '/')) part2 FROM TabA But for some reason, after certain rows the split seems to be not working properly. We are getting records like this, ColA part1 part2 1038627|21507470 1038627 21507470 1038627|21534857 1038627

How to count number of a particular event before another event in SQL Bigquery?

♀尐吖头ヾ 提交于 2019-12-08 03:49:39
问题 I have a table containing date and events and users. There is event named 'A'. I want to find out how many time a particular event occurred before and after event 'A' in Sql Bigquery. for Example, User Date Events 123 2018-02-13 X.Y.A 123 2018-02-12 X.Y.B 134 2018-02-10 Y.Z.A 123 2018-02-11 A 123 2018-02-01 X.Y.Z 134 2018-02-05 X.Y.B 134 2018-02-04 A The Output would be something like this User Event Before After 123 A 1 3 134 A 0 1 The event that I have to count contains a particular prefix.

Bigquery - json_extract all elements from an array

本秂侑毒 提交于 2019-11-27 18:54:58
问题 i'm trying to extract two key from every json in an arry of jsons(using sql legacy) currently i am using json extract function : json_extract(json_column , '$[1].X') AS X, json_extract(json_column , '$[1].Y') AS Y, how can i make it run on every json at the 'json arry column', and not just [1] (for example)? An example json: [ {"blabla":000,"X":1,"blabla":000,"blabla":000,"blabla":000,,"Y":"2"}, {"blabla":000,"X":3,"blabla":000,"blabla":000,"blabla":000,,"Y":"4"}, ] thanks in advance! 回答1: