I have two MySQL tables A and B both with this schema ID entity_id asset asset_type 0 12345 x 1 .. ……… ….. ………. I would like to get an aggregated top 10/50/whatever entity_ids with the largest row count difference between the two tables. I think I could do this manually by just getting the highest row count by entity_id
Tag: count
SQL query to consider exactly last 3 email send count and then return the respective click count
I have a table – ‘clicks_plus_noClicks_raw’ like below If customer has not clicked on any of the last 3 emails we sent(exact 3), I want to add the result to final table with count as 0. a@gmail.com & b@gmail.com should be skipped because we dint send them 3 emails yet.The final results should be only for ones we sent 3
Find the names of the suppliers who supply all the parts in MS Access
I have three tables: I want to find the names of the suppliers who supply all the parts in MS Access. This code does not work properly: What could be done better? Answer You need a CROSS join of Suppliers and Parts and a LEFT join to SPB. Then you group by supplier and set the condition in the HAVING
SQL query to count rows based on condition? Keep getting syntax error for my count logic
So I want my query to return how many books total as a column, but how many books are returned as a column. I’m using count also applying a condition, but I’m getting error saying: Incorrect syntax near ‘)’. Anyway to achieve this? Answer Here is the syntax error count(bookstatus = R) You can convert it like below
T SQL Count and Group by calculable column
This code gives the following table cntqueue cntdate cntINKTONERBLACK signalcolumn Queue01 2001-04-04 3 0 Queue01 2001-04-05 1 0 Queue01 2001-04-06 100 1 Is there a way to count ‘1’ in signal column and group 1st column to have? cntqueue NumberOfJumps Queue01 1 Answer You can use a subquery:
Best way to merge two SQL queries into one query
I have two small SQL queries that I would like to merge to be a single query that I will eventually use in a stored procedure. I have tried a CASE and IF/ELSE but could not get it to work. Below is the code. What I want to achieve is have the first column ‘Count of Open Order Lines’ based
SQL logic to fail a check if any of the related customers has failed
I have the requirement to flag the customers Y only when all the related customers have also passed the check. below are the two tables: relationship table : Check table I want output like below: output justification: since 1,2,3 are related customers and since one of them (3) has n in table 2 , so all the related customers should
Redshift SQL: Column Counting Matching Rows Given a Condition within another column
I have a table with two columns, user ids and strings. I want to add a third column that counts the number of strings within the second column that start with the entire string value in any given row. There is only one row per user. The goal is to get the following table structure: Here the count is equal
Sum of two counts from one table with additional data from another table
I have two tables as follows: I want to get the sum of two counts, which are the number of true values in col_a and number of true values in col_b. I want to group that data by user_id. I also want to join Table B and get the name of each user. The result would look like this: So
Count from 4 tables with join and null values
Tables: What I am expecting to query is this: However this is what I get: With this query: I wonder, in what way the query above could be modified to return the expected results? What would be a good approach to achieve this? Answer You are joining along two dimensions, so you are getting a Cartesian products. That is simply