¡Hola Forastero!

Pareces nuevo por aquí. Si quieres participar, ¡pulsa uno de estos botones!

In this Discussion

www.kplian.com
Para solicitar una invitación remitir un correo a info@kplian.com (Esta es una medida para evitar ataques de SPAM)

Ejemplo WITH consultas (Common Table Expressions) CTE

WITH regional_sales AS (
SELECT region, SUM(amount) AS total_sales
FROM orders
GROUP BY region
), top_regions AS (
SELECT region
FROM regional_sales
WHERE total_sales > (SELECT SUM(total_sales)/10 FROM regional_sales)
)
SELECT region,
product,
SUM(quantity) AS product_units,
SUM(amount) AS product_sales
FROM orders
WHERE region IN (SELECT region FROM top_regions)
GROUP BY region, product;

Comentarios

  • Otros ejemplo
    WITH parcial AS (
    SELECT 
                                id_partida as id_partida,
                                sum(importe_debe_mb) as importe_debe_mb,
                                sum(importe_haber_mb) as importe_haber_mb,
                                sum(importe_debe_mt) as importe_debe_mt,
                                sum(importe_haber_mt) as importe_haber_mt
                             FROM 
                                conta.vint_transaccion_analisis  v
     group by  
                                    id_partida,
                                    codigo_partida,
                                    descripcion_partida,
                                    sw_movimiento  ) 
                                    
     SELECT 
           count(id_partida) as total,
           sum(importe_debe_mb) as importe_debe_mb,
           sum(importe_haber_mb) as importe_haber_mb,
           sum(importe_debe_mt) as importe_debe_mt,
           sum(importe_haber_mt) as importe_haber_mt
    FROM parcial;   
Sign In or Register to comment.