SELECT CASE WHEN ORD_ID = (SELECT MAX(ORD_ID) FROM ORDERS_) AND ORD_ID%2 = 1 THEN ORD_ID WHEN ORD_ID%2 = 0 THEN ORD_ID-1 ELSE ORD_ID = 1 END CORRECT_ORD_ID, ITEM FROM ORDERS_
The correct query should be: SELECT CASE WHEN ORDer_ID = (SELECT MAX(ORDer_ID) FROM ORDERS_) AND ORDer_ID%2 = 1 THEN ORDer_ID WHEN ORDer_ID%2 = 0 THEN ORDer_ID-1 ELSE ORDer_ID +1 END CORRECT_ORD_ID, ITEM FROM ORDERS_ order by correct_ord_id
Please like and subscribe for more interesting SQL interview questions and answers.🙏
Very insightful, well explained
@@shrikrishnasoni11 Thank you so much ! I'm glad you found it insightful.
Well explained!!!
Keep it up!
Thank you!
Well explained
Thank you! 😊
SELECT
CASE WHEN ORD_ID = (SELECT MAX(ORD_ID) FROM ORDERS_) AND ORD_ID%2 = 1 THEN ORD_ID
WHEN ORD_ID%2 = 0 THEN ORD_ID-1
ELSE ORD_ID = 1
END CORRECT_ORD_ID,
ITEM
FROM ORDERS_
The correct query should be:
SELECT
CASE WHEN ORDer_ID = (SELECT MAX(ORDer_ID) FROM ORDERS_) AND ORDer_ID%2 = 1 THEN ORDer_ID
WHEN ORDer_ID%2 = 0 THEN ORDer_ID-1
ELSE ORDer_ID +1
END CORRECT_ORD_ID,
ITEM
FROM ORDERS_
order by correct_ord_id