SELECT `o`.`num`, `o`.`createdon`, `o`.`cost`, `o`.`status`, `p`.`products`
FROM `modx_ms2_orders` AS `o`
LEFT JOIN (
SELECT `order_id`,
JSON_ARRAYAGG(
JSON_OBJECT('name', `name`, 'price', `price`, 'count', `count`)
) AS `products`
FROM `modx_ms2_order_products`
GROUP BY `order_id`
) AS `p` ON `p`.`order_id` = `o`.`id`
WHERE `o`.`user_id` = 106
async function get_balance(user_id) {
return new Promise((resolve, reject) => {
conn.query(
`SELECT * FROM users WHERE user_id = ${user_id}`,
(err, result) => {
if (err) {
reject(err);
}
console.log(result[0].balance) // 0 (как и надо)
resolve(result[0].balance);
},
);
});
}
const result = await get_balance(ctx.message.from.id);
SET `cte_max_recursion_depth` = 10000;
INSERT INTO `test` (`DATE_CREATE`, `DATE_UPDATE`, `ACTIVE`, `USER_ID`, `VALUE`)
WITH RECURSIVE `cte` (`DATE_CREATE`, `DATE_UPDATE`, `ACTIVE`, `USER_ID`, `VALUE`) AS (
SELECT NOW(), NOW(), 1, 1, 1 AS `VALUE`
UNION
SELECT NOW(), NOW(), 1, 1, `VALUE`+1 FROM `cte` WHERE `VALUE` < 9999
)
SELECT *
FROM `cte`
SELECT `day`, `priority`, `count`
FROM (
(SELECT 'today' AS `day`, `priority`, COUNT(*) AS `count`
FROM `table`
WHERE `time` >= CURDATE() AND `time` < CURDATE() + INTERVAL 1 DAY
GROUP BY `priority`)
UNION ALL (SELECT 'yesterday', `priority`, COUNT(*)
FROM `table`
WHERE `time` >= CURDATE() + INTERVAL 1 DAY AND `time` < CURDATE() + INTERVAL 2 DAY
GROUP BY `priority`)
) AS `t`
The query cache is deprecated as of MySQL 5.7.20, and is removed in MySQL 8.0.
SELECT *
FROM `products`
JOIN (
SELECT MAX(`discount_price`) AS `max_price`, `product_id`
FROM `options`
GROUP BY `product_id`
) AS `max` ON `max`.`product_id` = `products`.`id`
ORDER BY `max`.`max_price` ASC
LIMIT 24
On Windows the default value is 1. On macOS, the default value is 2. On Linux, a value of 2 is not supported; the server forces the value to 0 instead.
You should not set lower_case_table_names to 0 if you are running MySQL on a system where the data directory resides on a case-insensitive file system (such as on Windows or macOS).
It is prohibited to start the server with a lower_case_table_names setting that is different from the setting used when the server was initialized.
SELECT *
FROM `shop` AS `s1`
LEFT JOIN `shop` AS `s2` ON `s1`.`price` < `s2`.`price`
Тогда вы увидите обе соединённые таблицы.SELECT *
FROM `shop`
ORDER BY `price` DESC
LIMIT 1