While I know the title isn't very specific and I apologise, I need help with a syntax issue I'm having with SQL, and as I'm not entirely sure as to the part of the syntax thats wrong, I can't be much more specific.
I'm using Oracle SQL Developer, if that helps.
SELECT DISTINCT pet.PET_NAME,
CASE
WHEN dog.PET_PET_NUMBER = pet.PET_NUMBER THEN 'Dog'
WHEN cat.PET_PET_NUMBER = pet.PET_NUMBER THEN 'Cat'
ELSE ''
END AS "Pet Type",
SUM(res.RESERVATION_START_DATE - res.RESERVATION_END_DATE) AS "Days Stayed"
FROM HVK_PET pet, HVK_DOG dog, HVK_CAT cat, HVK_RESERVATION res, HVK_PET_RESERVATION petRes
WHERE (pet.PET_NUMBER = dog.PET_PET_NUMBER
OR pet.PET_NUMBER = cat.PET_PET_NUMBER)
AND res.RESERVATION_NUMBER = petRes.RES_RESERVATION_NUMBER
AND petRes.PET_PET_NUMBER = pet.PET_NUMBER
GROUP BY pet.PET_NAME, dog.pet_pet_number, cat.pet_pet_number;
Is my complete code, the top 7 lines are underlined yellow with the suggestion to add CASE, to my group by statement. I'm not the greatest at SQL, so if it's glaring obvious don't hesitate to call me out on it.