I want pull out the date from second table. My second table may have a over 100 dates to a unique record(A,B,C). I have I first Table : and the second table : I want to first table pull out the date first date from second table when date is bigger than the date1 from first table. The result must
Tag: sql
Seed Data using merge statement including data from external table
I’ve been provided an excel file with data that I am supposed to merge into a database. From this data I am concatinating a string in this format: ‘Maastricht’ here is the name of a city, which I need up in a foreign table during the insert. This is the script that I have come up with: To Re…
Perform counting for lookup in SQL
I would like to perform lookup based on the number of Yes in Input. In ID No.1, Output1 is A because it is first Yes, Output2 is B because it is second Yes. In ID No.2, Output1 is blank because Input1 is n/a, subsequent output is based on number of Yes appeared. In ID No.3, it shows counting is skipped
id value needs a default value according to error 1364?
I want to create two tables. practice has a AUTO_INCREMENT attachment and is a PRIMARY KEY. continued has the id entity continued_id which exists as a FOREIGN KEY that references practice(user_id). Mysql executes the code below fine until line 19, where I receive the 1364 error, stating that continued_id has …
LIMIT and Contains in a single JSONB Query
I have 2 queries that separately run perfectly: This one limits the results: SELECT jsonb_agg(elem) as data FROM ( SELECT * FROM file_data, jsonb_array_elements(file_data) a(elem) LIMIT 3 ) …
MariaDB : an INSERT…SELECT with empty VALUES too
I want insert data from another incomplete table, so some values must be empty in NOT NULL fields. For example, I have two tables : people and peopleTemp. In people table, I have a lot of fields : permit_number, first_name, last_name, gender, tel, etc. In peopleTemp table, I have only permit_number, first_nam…
Find rows based on nested key in jsonb array
I have a jsonb column in Postgres 9.6 that contains JSON arrays of the following form: [ { “courses”: { “course-1”: { “graduated”: false }, “course-5”: { “graduated”: true } } }, { “…
SQL how to convert array to values for use in IN clause
Working in Postgres SQL: My query argument comes in as a comma separated string: ‘ABC,BCD’ I am trying to construct the query below, but getting an error: ERROR: Operator does not exist: character varying = text[] My question is how to convert ‘ABC,BCD’ to a list of values to use in th…
C# SQLConnection.Open() hangs, with no exception
I am using C# in Visual Studio 2019, with Xamarin.Forms, and SQl in SSMS 2018 and have the below code (where [] is used to replace unneccessary information) When I run this, it hangs indefinitely at connection.Open(). Debug mode continues to run and appears to move on from Connection.Open(), but never reaches…
Group rows by datediff and then use diff function
I have table in PostgreSQL with timestamp column created_at and integer column user_id. Each row represents some action from user. I need to calculate average user session length. Session is defined as group of actions with time difference less than 10 minutes. When there is difference 10 minutes or more betw…