SELECT c.cliente_id, c.cliente_nombre, c.cliente_telefono, c.cliente_blacklist_status, SUM(co.compra_precio) AS total_compra, ivr.ivr_num_src, ivr.ivr_num_dst, ivr.ivr_caller_channel, ivr.ivr_call_status, ivr.ivr_calldate FROM clientes AS c INNER JOIN compras AS co ON c.cliente_id = co.compra_cliente_id INNER JOIN ivr_calls AS ivr ON ivr.ivr_num_src = c.cliente_telefono AND ivr.ivr_call_status = 1 GROUP BY c.cliente_id, c.cliente_nombre, c.cliente_telefono, c.cliente_blacklist_status, ivr.ivr_num_src, ivr.ivr_num_dst, ivr.ivr_caller_channel, ivr.ivr_call_status, ivr.ivr_calldate
=========================================
SELECT
c.*,
(SELECT SUM(compra_precio)
FROM compras
WHERE compra_cliente_id = c.compra_cliente_id) AS total_compra
FROM
compras c;
SELECT t1.employee_id, t1.first_name, t2.order_id,t2.order_date FROM employees AS t1 INNER JOIN orders AS t2 ON t2.employee_id = t1.employee_id
-------------
SELECT *,
(SELECT balance_creditos
FROM balance
WHERE balance_cliente = (
SELECT balance_cliente
FROM balance
ORDER BY balance_creditos DESC
LIMIT 1
)
) AS balance_creditos
FROM clientes
WHERE cliente_id = (
SELECT balance_cliente
FROM balance
ORDER BY balance_creditos DESC
LIMIT 1
);
No hay comentarios:
Publicar un comentario