Skip to content
Advertisement

sql; concatenate MIN(price) and MAX(price) into column?

I am working on an aws athena query like so:

Which will give results like so:

enter image description here

Right now I have maxprice and minprice as two separate columns, but I want to combine them into one column “price range” which will have minprice and maxprice separated by a ” – ” string, so it would look something like this:

I tried doing this by adding CONCAT but wasn’t getting working results. Im very new to sql and am wondering how I could potentially create this price range column by combining the MAX() and MIN() results into a string value.

Also, I it possible to add logic to SQL so that if the price range is zero (like in the case of 2.22 – 2.22 where max price and minprice are identical) to just display a single value instead of a price range with identical max/min values?

this last part is a stretch goal, first im just trying to create the price_range column

Advertisement

Answer

Use concat()

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement