Ya estoy inscrito ¿Todavía no tienes acceso? Nuestros Planes
Ya estoy inscrito ¿Todavía no tienes acceso? Nuestros Planes
0
respuestas

ERROR HAGA LO QUE HICIMOS EN CLASES

En la ultima consulta de esa sección , la ultima consulta me arroja un error, pensé que la había escrito mal , pero luego la copie desde la plataforma a Mysql Workbench y un me da este error:

0	13	08:09:20	SELECT ENVASE, SABOR,
 CASE
    WHEN PRECIO_DE_LISTA >= 12 THEN 'Costoso'
    WHEN PRECIO_DE_LISTA >= 5 AND PRECIO_DE_LISTA < 12 THEN 'Asequible'
    ELSE 'Barato'
 END AS PRECIO, MIN(PRECIO_DE_LISTA) AS PRECIO_MINIMO
 FROM tabla_de_productos
 WHERE TAMANO = '700 ml'
 GROUP BY ENVASE,
 CASE
    WHEN PRECIO_DE_LISTA >= 12 THEN 'Costoso'
    WHEN PRECIO_DE_LISTA >= 5 AND PRECIO_DE_LISTA < 12 THEN 'Asequible'
    ELSE 'Barato'
 END
 ORDER BY ENVASE	Error Code: 1055. Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'jugos_ventas.tabla_de_productos.SABOR' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by	0.000 sec
Error Code: 1055. Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'jugos_ventas.tabla_de_productos.SABOR' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

La IA gemini me sugiere que hacer , pero no se si se va desconfigurar algo o no, lo dejaré así y avanzare el curso, espero me puedan orientar.

/* ====================================================================
   SOLUCIÓN AL ERROR 1055: ONLY_FULL_GROUP_BY (COLUMNA SABOR)
   ==================================================================== */

-- --------------------------------------------------------------------
-- OPCIÓN A: Agregar "SABOR" al GROUP BY
-- Usa esta opción si quieres ver el desglose detallado por cada sabor.
-- --------------------------------------------------------------------

SELECT 
    ENVASE, 
    SABOR, -- <--- Está en el SELECT
    CASE
        WHEN PRECIO_DE_LISTA >= 12 THEN 'Costoso'
        WHEN PRECIO_DE_LISTA >= 5 AND PRECIO_DE_LISTA < 12 THEN 'Asequible'
        ELSE 'Barato'
    END AS PRECIO, 
    MIN(PRECIO_DE_LISTA) AS PRECIO_MINIMO
FROM tabla_de_productos
WHERE TAMANO = '700 ml'
GROUP BY 
    ENVASE,
    CASE
        WHEN PRECIO_DE_LISTA >= 12 THEN 'Costoso'
        WHEN PRECIO_DE_LISTA >= 5 AND PRECIO_DE_LISTA < 12 THEN 'Asequible'
        ELSE 'Barato'
    END,
    SABOR -- <--- ¡Y ahora también está en el GROUP BY! Solucionado.
ORDER BY ENVASE;


-- --------------------------------------------------------------------
-- OPCIÓN B: Eliminar "SABOR" del SELECT
-- Usa esta opción si solo quieres agrupar por Envase y tipo de Precio,
-- tal como probablemente lo quería el reporte original del profesor.
-- --------------------------------------------------------------------

SELECT 
    ENVASE, -- <--- Se eliminó "SABOR" de aquí
    CASE
        WHEN PRECIO_DE_LISTA >= 12 THEN 'Costoso'
        WHEN PRECIO_DE_LISTA >= 5 AND PRECIO_DE_LISTA < 12 THEN 'Asequible'
        ELSE 'Barato'
    END AS PRECIO, 
    MIN(PRECIO_DE_LISTA) AS PRECIO_MINIMO
FROM tabla_de_productos
WHERE TAMANO = '700 ml'
GROUP BY 
    ENVASE,
    CASE
        WHEN PRECIO_DE_LISTA >= 12 THEN 'Costoso'
        WHEN PRECIO_DE_LISTA >= 5 AND PRECIO_DE_LISTA < 12 THEN 'Asequible'
        ELSE 'Barato'
    END
ORDER BY ENVASE;