Quote:
|
... you have substituted a non-standard function (IF) for my standard sql CASE expression ...
|
Ok sorry I didn't konw that, good to know.
Quote:
|
... you have needlessly double-quoted the column aliases ...
|
For me it's not needless because the alias can potentially contain spaces (that I never do but so anybody else can edit my query later)
Quote:
|
... you have needlessly parenthesized the join condition ...
|
For me it's not needless because the JOIN condition(s) can be multiple (and anyway it's the norm that I use for conditions in any langage)
indeed.
Finally if we want to be purists maybe we should do that
Code:
SELECT
articles.title
,
sum(
case
when comments.status=1
then 1
else 0
end) AS active
,
sum(
case
when comments.status=0
then 1
else 0
end) AS inactive
FROM
articles
LEFT JOIN comments
ON articles.id = comments.parent
GROUP
BY articles.title
