I want to get the records based on the row value. Please refer to the attached image for a table overview with records.
If there is no Execution Project
in the column projecttype
for a specific ESAProjectID
then take the row with values
projecttype='Group Project'
.
otherwise
if both Execution Project
and Group Project
are found for a specific ESAProjectID
then
take only projecttype='Execution Project'
In the attached image I have marked in green color records are the expected result.
I tried this SQL but no luck
SELECT DISTINCT a.ESAProjectID, a.projecttype
FROM test1 a
INNER JOIN test1 b
ON a.ESAProjectID = b.ESAProjectID
WHERE a.projecttype = 'Group Project'
3
Answers
If the version of the DB is 8.0+, then you can count by using a window aggregation function per each ESAProjectID value such as
Demo
Here’s another way:
Since
'Execution Project'
and'Group Project'
are the only possible values in the columnprojecttype
, you can do it withNOT EXISTS
: