Skip to content
Advertisement

Tag: aggregate-functions

SQL aggregate function on result of another aggregate function

Short backstory for this question. I am a student who works part-time as a tutor for several classes, including an entry level SQL class. I’ve got a student who has a fairly complicated database, compared to what most people get out of this class. Since their database ins’t super simple, they’e run into a problem trying to get a number.

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

PostgreSQL: aggregate records by time interval

I would like to generate reports of GPS capturing rate by travel modes. I have in a table modes the type of travel modes used by users. So for example, the following is the sample data for travel mode by user 10 for different trips. And then for each user and for each trip, user’s GPS traces are recorded in

Sum multiple columns in multiple rows

I have following data structure for sales: I need to know how many products with id=1 were sold for the last 12 month. If we are in June 2020 I need to sum M01, M02, M03, M04, M05 (WHERE year=2020) and M06, M07, M08, M09, M10, M11, M12 (WHERE year=2019) WHERE id=1. I should get a value of 36. Please,

When to Use * in SQL Query Containing JOINs & Aggregations?

Question Web_events table contain id,…, channel,account_id accounts table contain id, …, sales_rep_id sales_reps table contains id, name Given the above tables, write an SQL query to determine the number of times a particular channel was used in the web_events table for each name in sales_reps. Your final table should have three columns – the name of the sales_reps, the channel,

Advertisement