Skip to content

Tag: sql

Change MySQL query execution order

I want to put a entry in the database with id of 2. In order to do that I’m moving all records having more than 2 to id + 1. Because id is a primary key. This query is failing saying : #1062 – Duplicate entry ‘3’ for key ‘PRIMARY’. I know this is happening because query exe…

Want decimal result Amazon Redshift

I am trying to calculate the average ice creams a kid will have during summer. I want the result to have 2 decimals. Query: The result I get is something like 1.0003. I only want 2 decimal points. Any suggestions? Answer You can do this with round

Group by values that are each multiple of number

This is the table t. I want to group it every time the TotalQty >= 5n (let n = group). i.e. once the TotalQty >= 5n I want to sum together the qty from n-1 to n. With this query I can get pretty close but I doesn’t consider the the previous “valid” TotalQty + 5 — How do I

posgresql exclude zero division error results

I am executing a query but for sum cases this part of the code results into zero which causes zero division error.I am trying to not show result(not select) when Pease help. Answer The simplest way is to remove the else 0: This returns NULL if nothing matches the condition. Dividing by NULL produces NULL and …