I’m trying to produce a data set for a graph that would get me the same result as the following SQL query: But if I try to translate it into a linq query, I can’t get the same result, I either don’t have access to one or the other side of the junction, or I get a yearly total of
Tag: sql
Finding a phone number by entering a string SQL
I want to find the phone number in the database by entry into the string, while I wrote this. But if, for example, the number starts with +3 and not only with +7. Any help would be welcome. in SQL I am newbie For example, there is a Users table with a phone column. There are numbers starting at +
The difference between two values from different rows grouping by column
Let’s say there is a table jd_log: What im trying to do, is to find the difference between 2 durations (as duration_diff) for each unique job_name. It is guaranteed, that for each unique job_name there will be no more than 2 entries in the table with such job_name. If there is only 1 entry for specific job_name, duration_diff should be
Getting total from query of individual groups
I’ running a query that returns total count of offices per county. and my results look like this: Is there a way to get the total count returned in the same query? Answer If you want it as a column, use a window function: If you want it as an additional row, then use WITH ROLLUP:
SQL Query from getting SubChild to Child to Parent Tables
Good day, I’m trying to create a custom query for my scenario. Here’s the DEMO I created. Suppose I have 2 or more parent tables and this table will be consume by a child table. tblParent1 tblParent2 tblParent3 Then there’s a child table where it consumes these 3 parent tables. tblChild And the child of child table tblChildOfChild What I
Oracle: Id Not in another table
I have following two tables, airport and flying I would like to get airport_id where flying_id present in flying table but not present in airport table. I rote the following query using nested select query. Is there anyway I can improve without writing nested? Answer There are two ways. LEFT JOIN NOT EXISTS
SQL (BigQuery) Grouping Runtime Per Day
I have the following data which I want to group into seconds per day in BigQuery. Source Table: +————–+———————+———————+ | ComputerName | StartDatetime | EndDatetime | +————–+———————+———————+ | Computer1 | 2020-06-10T21:01:28 | 2020-06-10T21:20:19 | +————–+———————+———————+ | Computer1 | 2020-06-10T22:54:01 | 2020-06-11T05:21:48 | +————–+———————+———————+ | Computer2 | 2020-06-08T09:11:54 | 2020-06-10T11:36:27 | +————–+———————+———————+ I want to be able to visualise the data
Including only one row in sql [closed]
What I’m trying to do is take these records that looks like this: ID NAME STARTDATE ENDDATE EnrollmentMonth 1 PETER 20200705 20200729 20200701 1 TONY 20200730 99991231 …
How to pivot rows into a single comma separated string
Important update: When I try to use the suggested string_agg method I get this error – Specified types or functions (one per INFO message) not supported on Redshift tables. Original question I have a query but I’m struggling to “pivot” multiple rows into a single column of strings. I have a member and a category table and each member can
Postgres, split single row into multiple rows
I’ve got a table with columns like: I want to return: I ended out writing a large query using 3 unions like this, but this does not seem right: Is there a way to do this without the mess? Seems like I’m missing something really obvious. Answer In Postgres, you can efficiently unpivot the columns to rows with a lateral