Skip to content

Tag: sql

Gather the number of customer by street

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.…

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

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