Sorry, I hit the submit button a little to early 🙂
This is my best try:
$query = "SELECT *, "
. " CASE WHEN `DebTime` IS NULL THEN "
. " SUM( WorkTime ) as Value"
. " ELSE "
. " SUM( DebTime ) as Value"
. " END "
. " FROM `table`"
. " WHERE 1 "
. " GROUP BY `cusid` "
. " ORDER BY `cusid` ";
The problem is that if the DebTime column is empty, I want to sum the WorkTime column. And if both columns have a value, I want to sum the DebTime column.
So the result should be displayed as this (I don't want to sum the WorkTime in rows where there is a value in DebTime):
cusid Value
----- -----
1 15