I have two tables : Customer: id name address_id 1 John 4 2 Kate 5 3 Bob 2 4 Michael 2 5 Adriana 3 6 Ann 1 Address: id detail_str_name city district street_name 1 France,Paris,str.2,N5 Paris Paris str.2 2 France,Parise,str.2 ,N3 Paris Paris str.2 3 France, Lille ,str.3,N4 Lille Lille str.3 4 France,Paris,str.…
Tag: sql
Using Join and Union to combine results from 2 tables [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 9 months ago. Improve this question I already have a result set using join from multiple master tables with T…
How to only run left join when the variable is not null?
I’m trying to simplify my stored procedure and I have one that is only using left join based on the user id that is passed in. If the user id is null, don’t do left join, but if it is null, left join it with another table. How should I re-write it ? Thank you Answer Currently your stored procedure
DISTINCT from One table and INNER JOIN with another table in snowflake
I would like to: Join two tables Remove “queryGroupName” = ‘DELETE’ from the first table From the first table, get Id by deduping (distinct ID) Using this Id, inner join with another table For output, select only the second table SELECT “TABLE2”.* FROM (SELECT DISTINCT R…
Filtering out objects from multiple arrays in a JSONB column
I have a JSON structure with two arrays saved in a JSONB column. A bit simplified it looks like this Schema: Since each row (data column) can be fairly large, I’m trying to filter out matching item objects and group objects from the items and groups arrays. My current query is this which returns rows co…
How to use DENSE_RANK and order by aditional column?
I am trying to use dense_rank to get element order for instance: I have table seq_test with data: after I run the code above, I’ve got : I want to achieve: So DENSE_RANK() function use its own order defined in function definition I need to order the SEQ column by sequence column. Update: I want to get: …
Transforming SQL Query to Django Expression
Assuming I have the following Django models and the according SQL-Tables with some data. I have simplified the models so that it is clearer. UserAnswer: id answer partquestion_id 1 667 1 PartQuestion: id question_id part_id 1 1 1 Solution: id content question_id 1 667 1 2 85 2 I want to get all User answers w…
filter the result by ‘g / ml’ using SQL
I have the below table from which I need to filter which holds both “g / ml”. The below query gives me result as The expected result is What I can apply in the where clause to get the expected results Answer Just use %g/%ml%. The % can appear in any position in the matching pattern.
Postgres conversion rate
I want to get conversion rate in postgresql. My data look like below: input: id count type converted 1 30 A true 2 20 A false 3 13 B false 4 7 B true As first step, I would like to get a sum of counts for each type with associated count field. I tried with different variations of SUM()
MYSQL Query Age Calculation
This is my MySQL Query to return the age from the date of birth The query is executed. But it returns the age difference is in a negative value. Answer The problem with 2-digit year fixed – all years are treated as 19xx. https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=f356258c99b20d13b0c4e2349b801f18