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
SQL query – Records has at least one of the relationships specified – alternative?
I have 4 tables person, employments, properties, memberships How can I filter people that have at least one of the three relationships above? What I tried: Seems to be working, but it looks odd, and I am not sure if it’s the most efficient way of doing it. Any tips? Answer Your IN clauses are redundant.…
how do i add up on sql so it doesn’t double because group by
when i’m running my program, the results of the number instead make a number merge and make the number into many results. the results is this enter image description here Answer Seems you are trying to get the sum() per po number. lets put this in a subquery then join again those tables you want info to…
Convert day of year to date using proc sql in SAS
I have a day of year column and need to convert it to a date.I want to find the exact date that the insurance coverage began for every person. I also have a year column Have data: Want data: I searched up and find that the following command works in Oracle sql but does not work in SAS sql I
How to compose query properly using dbGetQuery command?
I have a small database in PostgresSQL. And I connected to it via R-studio and try to retrieve data from database. I wrote a command, but it doesn’t work. And I don’t know what’s the problem. Please, help me. So, the code works well. But these two codes fail Where con is the postgres connect…
Select customers who purchased BOTH this year and last
I’m fairly new to SQL and I’m using BigQuery to find customers who purchased in 2019 and 2018. This is the query I’m using to find the customers who purchased in 2019. SELECT DISTINCT contact_email …
Oracle SQL – Count, per month, how many times a site appears in the results
I’m not sure if I will explain this correctly so apologies in advance. I’m looking to put together a report that shows the number of times a site (central_site.site_code & central_site.site_name) …
Is there an elegant and efficient SQL way of listing all substring positions?
I have a text column in an sql database. My task is to find all occurrences of a given string in the texts, and list the character positions text by text (for backreference later in the application). …