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…
Tag: sql
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
select max, min row for each group without subquery with case of same [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago. Improve this question I’m trying to avoid sub queries because it generally takes longer to run. Came across …
How to merge two result columns into column with alternating results in oracle?
For a table with columns A and B, select * from table will give back A B A1 B1 A2 B2 A3 B3 Is there a way to query on this so that the result set is like this – Merged A1 B1 A2 B2 A3 B3 Appreciate any suggestions 🙂 Answer A union with some added spice to determine ordering would wo…
Column showing revenue increasing cumulatively, then only repeats the max value after a certain date
I’m creating a dashboard that, among other things, shows how much revenue a rep generated in their first month of joining the company. This is going to be based off a table I’m creating with SQL. The simplest version of this table will be: date (which will be every day of the week), rep name, reve…
Intersect two sf data.frames based on date and geometry using R
So, I have two R “sf” “data.frames”, one with millions of linestring geometries (vsr_segments: see below) and the other with 5 polygons (vsr_zones: see below). Each linestring has a datetime and each polygon has a unique date range. I’m trying to intersect the linestrings datafra…
Matching on Values, but Erroring on New Value in SQL Server
I am comparing data from two different databases (one MariaDB and one SQL Server) within my Node project, and am then doing inserts and updates as necessary depending on the comparison results. I have a question about this code that I use to iterate through results in Node, going one at a time and passing in …
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 …
SQL Union as Subquery to create Date Ranges from Start Date
I have three tabels, each of them has a date column (the date column is an INT field and needs to stay that way). I need a UNION accross all three tables so that I get the list of unique dates in accending order like this: Then I need to add a column to the result of the query where