SELECT p.author_id,
count(IF(pu.post_id IS NULL, 1, NULL))
FROM posts p
INNER JOIN author_user au ON p.author_id = au.author_id
LEFT JOIN post_user pu ON pu.post_id = p.id AND pu.user_id = au.user_id
WHERE au.user_id = :user_id
GROUP BY p.author_id
UPDATE table
SET alias = TRIM(LEADING CAST(alias AS SIGNED) FROM alias);
SELECT SUM(CASE WHEN MONTH('date') = MONTH(NOW()) THEN sum END) AS 'monthsum',
SUM(CASE WHEN WEEK('date', 1) = WEEK(NOW(), 1) THEN sum END) AS 'weeksum',
SUM(CASE WHEN DATE_FORMAT(date, '%Y-%m-%d') = CURDATE() THEN sum END) AS 'daysum'
FROM bills
WHERE YEAR('date') = YEAR(NOW());