I have table A and table B. Each row in table A represents every time a user sends a message. Each row in table B represents every time a user buys a gift. Goal: for each time a user sends a message, calculate how many gifts they’ve purchased within 7 days before the timestamp they sent the message. Some users
Tag: left-join
SQL GROUP BY with LEFT JOIN MS SQL Server
I have a calendar table (c) with a set of 3 month dates: I have a Stats table (s) with views of each product on the website. I need to count the views per product per month whether there are views or not. I have followed many SO answers (SQL – Group By with Left Join) and I cannot see
COUNT to return NULL as 0 in same table in SAS PROC SQL with GROUP BY
I am having a task where I have 1 table. There is a unique ID for transactions, transaction dates, and store names. My task would be to count the number of transactions every store made during March. This, in itself, is simple: This would lead to a table where a store is present only if it had a transaction in
How to calculate rows count in where statement in sql?
I have two tables in SQL Server: order (columns: order_id, payment_id) payment (columns: payment_id, is_pay) I want to get all orders with two more properties: How many rows where is_pay is 1: And the count of the rows (without the first filter) So I wrote this query: The problem is how to calculate the rows without the is_pay = 1?
Sql Join selecting records from A table and selecting matching records with a condition from B table
We have Table A and Table B, Data we need is in table A and we use table B to validate case where we have matching Ids. If ids do not match we can select it without validation, but if they match we need to check if date is in between date1 and date2. We only check records in B
Getting null data for left join on same table twice
I have some tables like this: Employee: Teams: TeamMember: I am trying to get list of employees with info regarding who they are : Team Member or Team Leader or Individual. Current output: Expected output: Query: Only issue here is that I am getting TeamId and TeamName as blank for “Team Leader” data as shown below: Current output: Can anyone
SQL Browser Crashing when running a Nested Query
I have a database with three tables: grocery nutrient grocery_nutrient (for many to many) Actually, the database is very big and I am facing the problems by running this query, the SQL browser crashes when I run, if I add LIMIT it works. and this is the query I have written for it. Answer You can simplify your query if
MySQL – category with product count not showing all results
I am trying to display the count of products along with the category name in the category list. I was able to achieve this with JOIN, but not all categories are displayed. I mean the categories with 0 products were not displayed, but I changed the JOIN to LEFT JOIN which displayed only one category with 0 products. There are
BigQuery SQL: How to find missing Values on comparing two tables over date range?
Have got two Bigquery tables as shown below: Table 1: Table 2: Scenario: Have to find missing Stores of Table 1 for each date comparing with Table 2 Stores. Expected Output: To list each missing Stores for each date on comparing. Tried Query: But this query doesn’t shows up the respective Report_Date, instead it shows ‘null’. Answer Using a calendar
GROUP CONCAT and LEFT OUTER JOIN to split
I’m working with SQL Workbench. This is an example of the tables I have: I have not created this DB and can’t modify it. Each building corresponds to a site, so it contains a KEY to such site. Same with levels and buildings. I am trying to get this result the first two columns are easy, but I’m having issues