Using While Loop in Postgresql - postgresql

This is my points table
I want to perform FIFO(First in First out) action
The column points has real time entries and considering the first two entries that is 600 and 400 respectively
I withdraw 900 totally i need to update the first column of redeemed_points as 600 and the second one as 300

Related

Pick rate calculation

I am trying to create an excel sheet that calculates average cases per hour based off of start time, end time, and total case count of the order. Ex. Employee A takes a 200 cs order at 0700 and completes by 0745. Employee B takes a 350 case order at 0715 and completes at 0920. Is it possible to create a spreadsheet with formulas that will calculate after entering the required data?
Looking for the pick rates per order, then would like to average on an 8 hour day per each employee.

Excel formula less than equal to 10 minute average for column

I have a range of approximately 1800 time increments (HH:MM:SS) in one column, sorted from low to high.
I am trying to come up with a formula that will produce the percentage of cells that are equal to or less than 10 minutes (10:00:00) of the approximately 1800 cells.
I'm not sure if I should be using AVERAGEIFS or another formula.
Thank you.
Some vagueness in the question. Is the time absolute and you want to compare among them or relative to a specified time. For the first case, you may very well use countif.
To get the cells less than equal to 10minutes:
countif(range,"<00:10:01")
Based on the comment, you can use this single formula:
=(COUNTIF(range,"<00:10:01")*100)/COUNTA(range)
The counta function gives you the number of non-blank cells in a range.

Create view or table

I have a table that will have about 3 * 10 ^ 12 lines (3 trillion), but with only 3 attributes.
In this table you will have the IDs of 2 individuals and the similarity between them (it is a number between 0 and 1 that I multiplied by 100 and put as a smallint to decrease the space).
It turns out that I need to perform, for a certain individual that I want to do the research, the summarization of these columns and returning how many individuals have up to 10% similarity, 20%, 30%. These values ​​are fixed (every 10) until identical individuals (100%).
However, as you may know, the query will be very slow, so I thought about:
Create a new table to save summarized values
Create a VIEW to save these values.
As individuals are about 1.7 million, the search would not be so time consuming (if indexed, returns quite fast). So, what can I do?
I would like to point out that my population will be almost fixed (after the DB is fully populated, it is expected that almost no increase will be made).
A view won't help, but a materialized view sounds like it would fit the bill, if you can afford a sequential scan of the large table whenever the materialized view gets updated.
It should probably contain a row per user with a count for each percentile range.
Alternatively, you could store the aggregated data in an independent table that is updated by a trigger on the large table whenever something changes there.

MATLAB: calculate with first row n times before moving to the next number

I am pretty new to Matlab and I could use some help. I have about 50k rows of data. What I would like to do is, that it would take the first number of the data, divide it by 12 and repeat the result 12 times then it would move on to the second number and do the same and so on and on till the end.
Best regards

Can I filter the same data differently in two columns in an Excel pivot table?

I've created a pivot table that lists the number of cases submitted by a series of locations.
Consider:
Location A 100
Location B 10
Location C 1000
TOTAL 1110
Our data for the table includes location and status. Now the client wants to see a percentage of CLOSED cases as a third column.
Consider:
Location A 100 50% (based on 50 cases marked as "closed")
Location B 10 10% (based on 1 case marked as "closed")
Location C 1000 20% (based on 200 cases marked as "closed")
TOTAL 1110 23% (based on 251 total cases marked as "closed")
I can add a third column to the table, but the second I filter on CLOSED cases, column two lists the totals of closed cases only, and my percentage is 100% for all of column three. Is there a way to leave column 2 selecting EVERYTHING, but set column one to look ONLY as closed cases?
In a perfect world, I could display location, count of ALL cases by location and count of CLOSED cases by location, expressed as a percentage of column #2
Is this doable?
I think the best way to do this is to add a column to your source data that assigns a 0 for open stores and a 1 for closed. Then using my dictum:
The percentage of True items in a list is the average of zeros and
ones, where True is represented by 1 and False by 0.
from this post, you can do this: