SELECT users.name AS username,
count(orders.id) AS orders_count
FROM users
JOIN orders ON orders.user_id=users.id
GROUP BY users.name
DROP PROCEDURE IF EXISTS get_artist;
DELIMITER ;;
CREATE PROCEDURE get_artist(IN artist_id integer(11), IN show_links integer(1))
BEGIN
CASE WHEN show_links=1
THEN
SELECT *
FROM artist
where id = artist_id;
ELSE
SELECT *
FROM artist
LEFT JOIN artist_social_links ON artist_social_links.artist_id = artist_id
where id = artist_id ;
END CASE;
END;;
DELIMITER ;
CALL get_artist(196796, 1);
CREATE TABLE test (entity INT, -- некая строка в структуре
position INT); -- её позиция при сортировке
UPDATE test
SET position := CASE WHEN position = @from
THEN @to
ELSE position + SIGN(@from - @to)
END
WHERE position BETWEEN LEAST(@from, @to) AND GREATEST(@from, @to);
SELECT *
FROM email
WHEN public.email.campaign_id IS NULL
SELECT *, 'false' AS campaign_id_bool
FROM email
WHEN public.email.campaign_id IS NULL
нужно, чтоб были значения и тру и фолс в зависимости от того пустое ли поле
SELECT *,
CASE WHEN public.email.campaign_id IS NULL
THEN 'false'
ELSE 'true'
END AS campaign_id_bool
FROM email
SELECT *,
ELT(1 + public.email.campaign_id IS NULL, 'true', 'false' ) AS campaign_id_bool
FROM email
SELECT a.login
FROM account a
JOIN transactions t ON a.id = t.account_id
JOIN game g ON t.game_id = g.id
JOIN company c ON c.id = g.Developer
GROUP BY a.login
HAVING !SUM( c.country != 'USA' OR YEAR(g.Release_date) MOD 2 )
что не так делаю?
CREATE TRIGGER tr
ON routes
AFTER INSERT
AS
UPDATE [user]
SET [update] = 1
FROM INSERTED
WHERE id = INSERTED.user_id;
SELECT `id_user`,
SUM(`sum`) `sum_month`,
SUM(`sum` * (`date` >= NOW() - INTERVAL 1 WEEK)) `sum_week`,
SUM(`sum` * (`date` >= NOW() - INTERVAL 1 DAY)) `sum_day`,
users.name
FROM `balance_history`
INNER JOIN `users` ON `id_user` = users.id
WHERE `date` >= NOW() - INTERVAL 1 MONTH
AND `type` = 'plus'
GROUP BY `id_user`, users.name
ORDER BY `sum` DESC
SUM(CASE WHEN {some condition}
THEN {some value}
ELSE 0
END)
SELECT html, REGEXP_REPLACE(html, '<nav>[^<]*</nav>', '')
FROM test;
UPDATE test
SET html = REGEXP_REPLACE(html, '<nav>[^<]*</nav>', '');