Skip to content

Tag: sql

SQLite – Rolling Average/Sum

I have a dataset as shown below, wondering how I can do a rolling average with its current record followed by next two records. Example: lets consider the first record whose total is 3 followed by 4 and 7 ,Now the rolling 3 day average for first record would be 4.6 and so on. Expected output: PS: Having &#822…

Join repeats rows too many times

List the employees (first and last name in same column), that work in retail or food and drink. Include the building they work in and shop type. This is what I have. Whenever I run it everything repeats so there’s over a hundred rows now. Can anybody help me? EDIT I’ve tried various joins for this…

can I use different hints in one clause of union in oracle

I have a merge query of below format – now I have to do union in this query My question is do I have to give parallel hint in second union clause also . Also use_hash hint which was running good earlier would not have impact on adding union clause in the query Answer The hints apply to each select

How do I fix ORA-01843: not a valid month?

So at the query level, I have it: And I’ve tried looking at a few articles with one most notable: How to change the date format in Oracle BI Publisher? I have also tried using: While going through structure and XML I noticed my date is in string format: element name=”DATETIME” value=”D…

PostgreSQL Percent Change using Row Number

I’m trying to find the percent change using row number with PostgreSQL but I’m running into an error where my “percent_change” column shows 0. Here is what I have as my code. Here is my SQL table in case it’s needed. Thank you in advance, I greatly appreciate it. Answer You can u…

Using COALESCE correctly in WHERE clause

Can someone explain why coalesce doesn’t work in the where clause given the following conditions below? How do we use coalesce correctly in this case without changing the below coalesce conditions and only for spoiled = Y? Table Fruit: Query: Using the query above will not return anything. Desired outpu…