Skip to content

Use SQL to find best 4 consecutive weeks

I have a dataset that has a product, weeknumber, and sales for that week. I am trying to find the 4 best consecutive sales weeks in the data, so for example, Product A’s 4 best weeks are 1-4 and Product S’s best weeks are 5-8 I am using SQL to query the table to return the 4 best consecutive weeks

Convention for IDs of child tables

Every tutorial that I watched implemented child tables with two IDs, one ID for the table itself, and one ID that was just a reference to the parent’s table ID, like so: In my project, I’m doing a discord bot, and the only identifier that I need is the server’s ID. There’s no need for …

select only those who have no contact

I updated my question. I have table like this: id name contact 1 A 65489 1 A 1 A 45564 2 B so, i want table like this: id name contact 2 B Answer Using exists logic we can try: In plain English, the above query says to return any records for which we cannot find another record belonging to

Multiple sum subqueries for percentage

I need help with the following problem: I want to make a query that contains multiples sums and then takes those sums and uses them to get a percentage: percentage= s1/s1+s2. I have as input the following data: Orders shipping date, Nb of orders that have arrived late, Nb of orders that have arrived on time W…

Union statement statement in SQLAlchemy

I have multiple large csv files that I want to merge and store the final table in a database for using in Pandas in the future. I read them all using Pandas and store them as separate but similar …