Skip to content

Tag: sql

Printing the same column twice

How can I print the ‘ID’ column twice. I’ve already got it in the start of the table, and also want it to also print out as the last column again for easy viewing purposes. ALTER TABLE EMPLOYEES ADD …

Select single value from same columns based on condition

I have below table and using oracle sql Result Question : Need query to get it. I have Tried MAX but not working Answer Assuming these are the only three conditions, you can use conditional aggregation: In Oracle, you can simplify this to: Here is a db<>fiddle. The keep syntax is getting the last value …

Questions on aggregation

I am required to find the name of the product (iname) where total delivery quantity is equal to the total sales quantity Two tables given are I tried this code but the result I got is aggregated incorrectly because there are multiple sales and deliveries of the same item When I do the following I was able to …

Datediff on 2 rows of a table with a condition

My data looks like the following Now, I want to calculate the datediff between the closeddates for teams A, and B, if the max closeddate for team A is greater than max closeddate team B. If it is smaller or null I don’t want to see them. So, for example,I want to see only one record like this : and