0

Shipping address to persons contain multiple text inside it , for example in this 4 Rows of consumer address.

     |         Address Line                 |
     |--------------------------------------|
     |APARTMENT 5800 springfield GARDENS CIR|
     |--------------------------------------|
     |APT 5800 springfield GARDENS CIR      |
     |--------------------------------------|
     |2567 south pay street                 |
     |--------------------------------------|
     |Office 222 Market , VA 048946         |

How can i add another column that contain certain character such as Address Line contain "Apartment" or "APT" will become "Apartment" and Address Line contain "Street" will become "Household" , Address Line contain "Office" will become "Office building" and "Unknown" for Address Line not included.

This is the desired table after the query included with PostgreSql

         |         Address Line                 |      Location      |
         |--------------------------------------|--------------------|
         |APARTMENT 5800 springfield GARDENS CIR|   Apartement       |
         |--------------------------------------|--------------------|
         |APT 5800 springfield GARDENS CIR      |   Apartement       |
         |--------------------------------------|--------------------|
         |2567 south pay street                 |   Household        |
         |--------------------------------------|--------------------|
         |Office 222 Market , VA 048946         |   Office building  |
         |--------------------------------------|--------------------|

This is my query :

 SELECT ORDER_TABLE.guest_email,
        CASE WHEN ORDER_SHIPPINGADDRESS.LINE1 IN ('Apartement', 'apt') Then 'Apartement'
        WHEN ('street') then 'household'
        WHEN ('Office') then 'Office Building'
        ELSE 'Location Unknown' END as Location

My trial so far by using Case When however it ended error like this

ERROR: argument of CASE/WHEN must be type boolean, not type record

Are there any functions that can do the desired table above? thanks

1 Answer 1

1

You should repeat ORDER_SHIPPINGADDRESS.LINE1 INin each WHEN

SELECT ORDER_TABLE.guest_email,
    CASE WHEN ORDER_SHIPPINGADDRESS.LINE1 IN ('Apartement', 'apt') Then 'Apartement'
         WHEN ORDER_SHIPPINGADDRESS.LINE1 IN ('street') then 'household'
         WHEN ORDER_SHIPPINGADDRESS.LINE1 IN ('Office') then 'Office Building'
    ELSE 'Location Unknown' END as Location
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.