I have a query something like this: But now, I want to see the top 10 product_id for each site and category_id based on the clicks. When I write the LIMIT function, it only shows the top 10 products but it does not group it by category_id and shop_id. How can I do this? Answer Use window functions. You can
Tag: sum
Get aggregated average values joining three tables and display them next to each value in first table
I have three tables which you can also find in the SQL fiddle: CREATE TABLE Sales ( Product_ID VARCHAR(255), Sales_Value VARCHAR(255), Sales_Quantity VARCHAR(255) ); INSERT INTO Sales (…
SQL sum grouped by field with all rows
I have this table: I want this result: I tried this: But get the error that subquery returns different number of rows. How can I do it? I want all the rows of sale_lines table selecting all fields and adding the sum(price) grouped by sale_id. Answer You can use window function : If you want sub-query then you need to
Multiple SUM in one query with multiple where
I’m trying to write a SQL query that produces a table with summarized values for each year and month. I have a table that looks something like this: And another table that looks like this: I want to have a query that returns the sum for each month like this: Explanation of the output: Year and Month are obvious RegTime
Creating extra columns based on condition (Case When Sum)
I have survey table where someone is asked roughly 5 questions. 4 of those questions are the same questions, but the options to their answers are different since they were to understand their purchase. Here are the questions: The goal is to create four extra columns based on their answer and they will be assigned a 1 or 0. Since
SUM of TotalSellPrice, Grouped by JobID? – Beginner SQL Question
I’m looking to write a query that gives the YTD sales for each job within our system. We use Bistrack. Here is what I have: select C.Shortname AS “Customer”, J.JobReference, (OH.TotalSellPrice – OH….
Grouped conditional sum in Oracle SQL
my_table shows the account balance of each person’s credits N months ago. From this table, I want to get the monthly sum of each person’s balances for the past 2 and 3 months and divide each sum by 2 …
Is there anybody who can help me with mysql query?
SELECT (SELECT SUM(kwh) FROM energy_logger WHERE TIME >= ’05:30:00′ AND TIME = ’18:30:00′ AND …
How do I sum up each Month of data for each product?
I have a set of data such as: Date Product Volume 01-01-2020 A 5 02-01-2020 A 25 03-01-2020 B 20 02-01-2020 B 10 04-01-2020 C 5 02-02-2020 …
Cumulative Sum When rows have the same value sql sql server
I’d like to do cumulative sum of the column SubTotal to get a cumulative RunningTotal column. But I noticed that if rows have the same values, the cumulative sum doesn’t work. e.g. In the below example, the row 5 and row 6 have the same SubTotal value of 838.9178. Because of that, the RunningTotal column doesn’t sum up for row