SELECT @Code=t1.КодТовара, @Итог=t1.Количество, @Имя=t2.Наименование
FROM (
SELECT КодТовара, SUM(Количество) AS Количество
FROM Заказ
WHERE ДатаЗаказа BETWEEN GetDate()-@Интервал AND GetDate()
GROUP BY КодТовара
) AS t1
JOIN Товар AS t2
ON t2.КодТовара = t1.КодТовара
ORDER BY t1.Количество * IF(@ТипРезультата = 1, 1, -1) object yii\db\ActiveQuery [
"sql" => "SELECT * FROM clients WHERE id_cart = 9455958663",
"on" => null,
"joinWith" => null,
"select" => null,
"selectOption" => null,
"distinct" => null,
"from" => null,
"groupBy" => null,
"join" => null,
"having" => null,
"union" => null,
"params" => [],
"queryCacheDuration" => null,
"queryCacheDependency"=> null,
"yii\base\Component_events" => [],
"yii\base\Component_eventWildcards" => [],
"yii\base\Component_behaviors" => [],
"where" => null,
"limit" => null,
"offset" => null,
"orderBy" => null,
"indexBy" => null,
"emulateExecution" => false,
"modelClass" => "frontend\models\Clients",
"with" => null,
"asArray" => null,
"multiple" => null,
...
]1. Let V be undefined.
2. Perform ? CreatePerIterationEnvironment(perIterationBindings).
3. Repeat,
a. If test is not [empty], then
i. Let testRef be the result of evaluating test.
ii. Let testValue be ? GetValue(testRef).
iii. If ToBoolean(testValue) is false, return NormalCompletion(V).
b. Let result be the result of evaluating stmt.
c. If LoopContinues(result, labelSet) is false, return Completion(UpdateEmpty(result, V)).
d. If result.[[Value]] is not empty, set V to result.[[Value]].
e. Perform ? CreatePerIterationEnvironment(perIterationBindings).
f. If increment is not [empty], then
i. Let incRef be the result of evaluating increment.
ii. Perform ? GetValue(incRef). А если мне необходимо к примеру, что бы один клиент имел связь с двумя типами, с двумя записями в таблице №1?Это уже связь многие-ко-многим. Организуется промежуточной таблицей, каждая запись которой связывает пару из первой и второй основных таблиц.
ORDER BY `id` = :id DESC, `date`1,"Продукты и сырье"
1.1,"IT продукты"
1.2,"Автозапчасти и аксессуары"
1.2.1,"Аксессуары"
1.2.2,...
1.3,...
2,...