Benutzer mit den meisten Antworten
SQL Query If ... return tabel

Frage
-
Hello!
My tabel:
JobID|JobDateTime|Result
1| time1| intval1
1| time1| intval1
1| time1| intval1
2| time1| intval2
2| time1| intval1
2| time1| intval2
1| time2| intval3
1| time2| intval2
2| time2| intval1
...Well, first of all I want get the last entries like:
JobID|JobDateTime|Result
1| time1| intval1
1| time1| intval1
1| time1| intval1
2| time1| intval2
2| time1| intval1
2| time1| intval2Query:
select T1.JobID, T2.JobDateTime, Result from T1
join (select JobID, MAX(JobDateTime) as JobDateTime from T1 group by JobID)T2
on T1.JobID = T2.JobID and T1.JobDateTime = T2.JobDateTimethat was the easy part.
Now, I want to get a tabel with one row for each Job. Condition: If a Job has one result unlike intval1 return JobID|time1|intval2 else return JobID|time1|intval1 like:
JobID|JobDateTime|Result
1| time1| intval1
2| time1| intval2In other words, I want to use these intval (integer value) as boolean expressions. Ideas?
Antworten
-
- Als Antwort vorgeschlagen Falk Krahl Donnerstag, 15. September 2011 10:57
- Als Antwort markiert Robert BreitenhoferModerator Mittwoch, 21. September 2011 14:42
-
Well, maybe the description was bit confusing.
I got it. It works with "group by"
but thanks for reply!
- Als Antwort markiert Robert BreitenhoferModerator Mittwoch, 21. September 2011 14:42
Alle Antworten
-
- Als Antwort vorgeschlagen Falk Krahl Donnerstag, 15. September 2011 10:57
- Als Antwort markiert Robert BreitenhoferModerator Mittwoch, 21. September 2011 14:42
-
Well, maybe the description was bit confusing.
I got it. It works with "group by"
but thanks for reply!
- Als Antwort markiert Robert BreitenhoferModerator Mittwoch, 21. September 2011 14:42