livesklad/sql_fullquery.txt

20 lines
407 B
Plaintext

SELECT
o.orderId,
c.name,
GROUP_CONCAT(DISTINCT(cph.phone_number) SEPARATOR ';') AS phone,
o.dateCreate,
o.dateClose,
o.shopId,
o.statusId,
o.summPrice,
o.purchasePrice
FROM
orders o
LEFT JOIN counteragents c ON c.id = o.counteragentId
LEFT JOIN counteragents_phone cph ON c.id = cph.counteragent_id
WHERE
o.dateClose IS NULL
GROUP BY c.id
ORDER BY dateCreate DESC
LIMIT 30