Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Alexd91
Starting Member
2 Posts |
Posted - 2014-01-11 : 16:47:06
|
Hello, I joined different tables and got a result like this: result | process | goal | date |------- ---------- ------ -----------ok | process4 | 1 | 12.10.2013bad | process1 | 2 | 13.10.2013ok | process1 | 4 | 12.12.2013good | process4 | 1 | 03.01.2014ok | process1 | 3 | 10.04.2013bad | process3 | 6 | 09.01.2014bad | process4 | 3 | 30.12.2013best |NULL| NULLNow I want to count the results by counting the processes and group them by the result. But it should be count the latest result per process only, e.g. for goal "1" just "good" at 03.01.2014. I solved that with a subquery (date=SELECT MAX(...)..). But now the result "best" disappears, because that column has no date. Secondly I want to count results for a specific process, e.g. for process4. Every goal has max. one process, with different dates. But one process could have more than one goal.I want to have this result for process4:count | result------ -------1 | good1 | bad0 | ok0 | bestBut I got only:count | result------ -------1 | good1 | badI have tried a lot, but nothing works. The whole result (best, good, ok, bad) are stored in an other table and I joined it. Could somene help me? It would be very great :)Thanks,Alex |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-01-12 : 01:37:12
|
Can you explain your output. How did you get 0 for on for process4? you've record belowok | process4 | 1 | 12.10.2013so shouldnt it be 1 for ok?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
Alexd91
Starting Member
2 Posts |
Posted - 2014-01-12 : 07:02:53
|
No, because it should only count the latest date and result for each goal. For goal = 1:ok | process4 | 1 | 12.10.2013good | process4 | 1 | 03.01.2014And 03.01.2014 > 12.10.2013 so, +1 for good.But that works fine, i just want to have the result with 0 when count=0. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-01-12 : 14:20:20
|
quote: Originally posted by Alexd91 No, because it should only count the latest date and result for each goal. For goal = 1:ok | process4 | 1 | 12.10.2013good | process4 | 1 | 03.01.2014And 03.01.2014 > 12.10.2013 so, +1 for good.But that works fine, i just want to have the result with 0 when count=0.
Sorry I dont understand . In first post you specified you run it for each process. Can you tell me how you got bad as 1? bad for process4 is on 30.12.2013 which is not latest date.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
IleanaAlvare
Starting Member
7 Posts |
Posted - 2014-01-31 : 09:59:21
|
Hey Alex,Did you find a way to solve this problem? |
|
|
|
|
|
|
|