Skip to content
Advertisement

Tag: window-functions

Postgres Calculating Weighted Average

I am trying to get the weighted average of items from this example table: Item Value Item1 0.10 Item2 0.15 I followed this example here how to calculate it: https://www.wikihow.com/Calculate-Weighted-Average And tried this statement: I am trying to get the average by doing SUM(numberXWeightingFactor) but it doesn’t work. Ends up giving me error: column “numberxweightingfactor” does not exist. Answer Multiple

How to remove and carry forward month prior when running balance decreases?

I have the following data: client_id balance_month balance 100000000 September 1,2021 12:00 AM $7000 100000000 August 1,2021 12:00 AM $7000 100000000 July 1,2021 12:00 AM $6000 100000000 June 1,2021 12:00 AM $3000 100000000 May 1,2021 12:00 AM $20000 100000000 April 1,2021 12:00 AM $1000 100000000 March 1,2021 12:00 AM $0 200000000 September 1,2021 12:00 AM $7000 200000000 August 1,2021 12:00

How to make revenue $0 for months prior to decrease in SQL?

I have the following data: client_id balance_month balance 100000000 September 1,2021 12:00 AM $400 100000000 August 1,2021 12:00 AM $100 100000000 July 1,2021 12:00 AM $200 100000000 June 1,2021 12:00 AM $300 200000000 September 1,2021 12:00 AM $99 200000000 August 1,2021 12:00 AM $100 200000000 July 1,2021 12:00 AM $100 200000000 June 1,2021 12:00 AM $100 What is the most

How to add data to a field based on other fields in a SQL database

I have an SQLite table called wcvp constructed from a csv file downloaded from the World Check List of Vascular Plants (see https://wcvp.science.kew.org/ and http://sftp.kew.org/pub/data-repositories/WCVP/). When I run this query: I get this result: kew_id genus species infraspecies 304293-2 Quercus robur 77189540-1 Quercus robur broteroana 77189379-1 Quercus robur brutia 77189383-1 Quercus robur imeretina 60459295-2 Quercus robur pedunculiflo 77171868-1 Quercus robur

Lead window function in mysql to find sales

Given this table. I would like to know for each day how many different customers made a sale on date t and and t+1. The result for date 2021-06-30 is 2 because customer 1 and 3 made a sale in t and t+1. Answer Use LEAD() window function for each distinct combination of date and customer to create a flag

Advertisement