I’m trying to write a query that counts the number of products from a supplier group that are on a specific state or return 0 if it doesn’t have products. This query will only return the count if the …
Tag: sql
How do i use a cursor correctly
With the code below I am trying to search for certain words (SEED WORDS) inside reviews. Then depending on the number of Seed words inside each review I come up with a rating number. There are …
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 …
How to use a list/array of values as column name in select statement?
Say I have 3 list of data that I am using to build a new query. I need to take these list of data and return the values of those list where things were found. So my question is this: Is there a standard method of taking a list and using it as a column? I will need to use
Pivoting SQL table with crosstab function
I made this query that lists all real estate prices per m2 per year in a city. It works nice yet all years end up in rows, with the prices behind them. I would prefer seeing the years in columns with …
Is there an equivalent to TRY_CONVERT() in Oracle?
TRY_CONVERT() in T-SQL would return a value cast to the specified data type if the cast succeeded; otherwise it would return NULL. Is there a similar function in ORACLE or a way to reproduce this …
Redshift: Find max level of previous mode
I have a user table that store level of each category completion. User can unlock the second and the third category after a few levels of the first category completion. My goal is to find which level …
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