Skip to content

Tag: sql

Calculate Time Between Logins by User in Bigquery

I am trying to calculate the time difference between 2 login events in BigQuery, by user. I want to understand how long it takes between logins for each user. I’ve tried with the following query: Sample Data user_id event timestamp aaa Login 2021-02-20 00:00:00 UTC bbb Login 2021-02-20 00:02:00 UTC aaa …

Create Athena table using JOOQ java

How can I create a Athena table using jooq library in java. Since Athena table uses syntax like create external table and we need to specifiy s3 bucket path also. I have a list of string from which i want to create the athena table. Can somebody suggest a way how i can do it with jooq library. Answer Amazon

How create Postgres database using SQLAlchemy

I want write project using database library (SQLAlchemy). When I use SQLite, all works good, but when I deploy project on server (Heroku with Postgres plugin), It doesn’t work. This is code for my database: I have engine & Base variable: In DATABASE_URL link to base on Heroku(Postgres). For create d…

SQL – Selecting rows based on date difference

Suppose we have below table: Code Dt c1 2020-10-01 c1 2020-10-05 c1 2020-10-09 c1 2020-10-10 c1 2020-10-20 c2 2020-10-07 c2 2020-10-09 c2 2020-10-15 c2 2020-10-16 c2 2020-10-20 c2 2020-10-24 Combination of Code and Dt is unique. Rows are sorted based on Code and Dt. Database is Oracle 12. For every code, I wa…

Trigger to update a table whenever there is an insert

I am trying to use a trigger (in SQL Server) to update a table whenever there is an insert on the table but I get an error: Conversion failed when converting date and/or time from character string. Trigger used: The table table_scan is to be updated when there is NULL in start_date after an insert happens. An…