I have a 2 tables with the same structure: table1 id text var 1 “bla bla” 100 1 “blabla1” 30 2 “qweweqty” 0 2 etc… 7 3 3 1 .. 100 table2 id text …
Tag: group-by
GROUPING multiple LIKE string
Data: In above data, there are 3 kinds of strings I am interested in warning, error and timeout Can we have a single query where it will group by string and give the count of occurrences as below Output: I know I can write separate queries to find count individually. But interested in a single query Thanks Answer You can
SQL Query with Group , Order by and Random at the same time
I was unable to find anything similar to this problem. As we see John and David has more than one row and there’s a Order column so we can order it simply using ORDER BY Name ASC, Order ASC but this is not exactly what i need.. Here is the problem: i would like to know if its possible to
Match duplicate value from the second column based on duplicate value from first colum
I have table like this I have two condition for this table which is : Val column must be duplicate value AND, Val2 column must be duplicate so my goal is return data if the two condition meet. If the column val had duplicate value and column val2 had duplicate value and each column on his own row. my query
Why there is no GroupBy clause in internal SQL of Entity Framework linq query?
In documentation of Entity Framework: https://www.entityframeworktutorial.net/querying-entity-graph-in-entity-framework.aspx in section regarding GroupBy we can read that following code: executes internally following SQL: Why there is no GroupBy clause in SQL? If there is no GroupBy clause needed, can’t we just use simple Select with OrderBy and without Joins? Can anyone explain the above query? Answer The bottom line is: because SQL can’t
SQL Server Concatenate three different columns into a Comma-Separated without repeated values
The next table is a simplification of my problem in SQL Server: I want to get a group with the columns concatenated by comma without repeated values. I tried to use STRING_AGG() but it returns: This is the query I have done: I would like the next result: Thank you! Answer Without using window functions. The union might slow things
MySQL: Why are these two wrong? (Invalid use of group function, selected nothing after using having())
Credit:Leetcode_1076.Project Employees II Here is the sample table Project table: (project_id, employee_id) is the primary key of this table. I have tried several methods and managed to find the right one by using dense_rank(); however, I still don’t understand why these two syntaxes are wrong to select project_id with the largest number of employees: 1.Return null: {“headers”: [“project_id”, “n”], “values”:
How to use SQL find first matching result from one table in another table?
Suppose I had two tables: What I want to do is write a query that will find the first sale for each customer. I am not sure exactly how to do it. I feel like this is group by problem, but the answer is not coming to me. EDIT: I feel like my first data table did not fully explain
Check if multiple records exist, with the same id
I am trying to check if multiple records exists with pageId IN(?,?,?) in the chatParticipants table. This is an example of the table structure: This is the SQL query I have tried: Expected behavior: If a conversation already exists, with the given (x) participants, that is, with the same chatId value, then it must return the chatId value. The above
How do I create cohorts of users from month of first order, then count information about those orders in SQL?
I’m trying to use SQL to: Create user cohorts by the month of their first order Sum the total of all the order amounts bought by that cohort all-time Output the cohort name (its month), the cohort size (total users who made first purchase in that month), total_revenue (all order revenue from the users in that cohort), and avg_revenue (the