x OR y OR z AND q
будет выполняться как x OR y OR (z AND q)
, так как приоритет у AND выше, чем у OR.SELECT `time`, `ticker`, `price`, `volume`,
`icon`, `tf`, `figure`, `figure_text`
FROM `figure`
WHERE `figure` IN ('vklin', 'nklin', 'doublev', 'doubled', 'mflag', 'bflag', 'flag')
AND `tf` IN ('1h', '4h', '1d')
UNION SELECT `time`, `ticker`, `price`, `volume`,
`icon`, `tf`, `situation`, `situation_text`
FROM `levels`
WHERE `situation` = 'resistance'
AND `tf` IN ('1h', '4h', '1d')
SELECT `p`.*,
COUNT(`op`.`id`) AS `ordersCount`,
IFNULL(SUM(`op`.`count`), 0) AS `countOrdersCount`
IFNULL(SUM(`op`.`price` * `op`.`count`), 0) AS `ordersSum`
FROM `products` AS `p`
LEFT JOIN `orders_products` AS `op` ON `op`.`item_id` = `p`.`id`
LEFT JOIN `orders` AS `o` ON `o`.`id` = `op`.`order_id`
AND `o`.`date` > '2020-01-01'
AND `o`.`status` != 2
WHERE `p`.`active` = '1'
GROUP BY `p`.`id`
ORDER BY `p`.`id` DESC
LIMIT 0, 25
CREATE TABLE "table" (
field1 VARCHAR(16),
field2 INT GENERATED ALWAYS AS (
ARRAY_POSITION(ARRAY['value1', 'value2', 'value3', 'value4'], field1::TEXT)
) STORED
);
CREATE TABLE "table" (
field1 VARCHAR(16),
field2 INT GENERATED ALWAYS AS (
(ARRAY[0, 11, 22, 44])[ARRAY_POSITION(ARRAY['value1', 'value2', 'value3', 'value4'], field1::TEXT)]
) STORED
);
CREATE TABLE "table" (
field1 VARCHAR(16),
field2 INT GENERATED ALWAYS AS (
CASE field1
WHEN 'value1' THEN 0
WHEN 'value2' THEN 11
WHEN 'value3' THEN 22
ELSE 44
END
) STORED
);
user_id соответсвует количеству зарегистрированных клиентов и написал следующий кодНеудачное решение. Нет никаких гарантий, что id будут идти строго последовательно.
WITH RECURSIVE `dates` (`date`) AS (
SELECT '2021-06-01'
UNION
SELECT `date` + INTERVAL 1 DAY
FROM `dates`
WHERE `date` < '2021-06-30'
)
SELECT `d`.`date`, MAX(`c`.`count`) OVER `win` AS `registered`
FROM `dates` AS `d`
LEFT JOIN (
SELECT DISTINCT `date`, COUNT(*) OVER `win` AS `count`
FROM `registers`
WINDOW `win` AS (ORDER BY `date`)
) AS `c` ON `c`.`date` = `d`.`date`
WINDOW `win` AS (ORDER BY `d`.`date`)