Why doesn't the next job work?
SELECT SUM(startUserThreads.newForStartUser)+SUM(endUserThreads.newForEndUser) AS numNew ...
It returns an empty string.
Next returns 1 for my dataset:
SELECT SUM(startUserThreads.newForStartUser) AS numNew ...
How can I add two amounts correctly?
All:
SELECT t.*,
COUNT(startUserThreads.id) + COUNT(endUserThreads.id) AS numThreads,
SUM(startUserThreads.newForStartUser) + SUM(endUserThreads.newForEndUser) AS numNew
FROM `folder` `t`
LEFT OUTER JOIN `thread` `startUserThreads`
ON ( `startUserThreads`.`startUserFolder_id` = `t`.`id` )
LEFT OUTER JOIN `thread` `endUserThreads`
ON ( `endUserThreads`.`endUserFolder_id` = `t`.`id` )
WHERE user_id = :user
FYI, only two users can share the stream in my model. This should explain the column names.
Jonah source
share