SQL - SQL join

 
Vista:

SQL join

Publicado por dan (1 intervención) el 12/12/2021 23:44:49
Hola tengo el siguiente query
WITH temp_table AS (
SELECT storekeeper_id AS rt_id, cycle_order,
CASE
WHEN mobile_acceptance >= acceptance_threshold_diamond THEN 'diamond'
WHEN mobile_acceptance >= acceptance_threshold_silver THEN 'silver'
WHEN mobile_acceptance < acceptance_threshold_silver THEN 'bronze'
ELSE Null END AS acceptance_clas,
CASE
WHEN mobile_completion >= completion_threshold_diamond THEN 'diamond'
WHEN mobile_completion >= completion_threshold_silver THEN 'silver'
WHEN mobile_completion >= completion_threshold_bronze THEN 'bronze'
ELSE Null END AS completion_clas,
CASE
WHEN mobile_rating_fix >= rating_threshold_diamond THEN 'diamond'
WHEN mobile_rating_fix >= rating_threshold_silver THEN 'silver'
WHEN mobile_rating_fix >= rating_threshold_bronze THEN 'bronze'
ELSE Null END AS rating_clas,
CASE
WHEN mobile_slots_assisted >= slots_threshold_diamond THEN 'diamond'
WHEN mobile_slots_assisted >= slots_threshold_silver THEN 'silver'
WHEN mobile_slots_assisted < slots_threshold_silver THEN 'bronze'
ELSE Null END AS slots_clas,
CASE
WHEN mobile_hdh >= hdh_threshold_diamond THEN 'diamond'
WHEN mobile_hdh >= hdh_threshold_silver THEN 'silver'
WHEN mobile_hdh < hdh_threshold_silver THEN 'bronze'
ELSE Null END AS hdh_clas,
CASE
WHEN mobile_closed_orders >= orders_threshold_diamond THEN 'diamond'
WHEN mobile_closed_orders >= orders_threshold_silver THEN 'silver'
WHEN mobile_closed_orders < orders_threshold_silver THEN 'bronze'
ELSE Null END AS orders_clas,
CASE
WHEN mobile_attendance >= orders_threshold_diamond THEN 'diamond'
WHEN mobile_attendance >= orders_threshold_silver THEN 'silver'
WHEN mobile_attendance < orders_threshold_silver THEN 'bronze'
ELSE Null END AS attendance_clas,
CASE
WHEN acceptance_clas = 'bronze' THEN 1
WHEN completion_clas = 'bronze' THEN 2
WHEN attendance_clas = 'bronze' THEN 3
WHEN slots_clas = 'bronze' THEN 4
WHEN orders_clas = 'bronze'THEN 5
WHEN hdh_clas = 'bronze' THEN 6
WHEN rating_clas = 'bronze' THEN 7
WHEN acceptance_clas = 'silver' THEN 8
WHEN completion_clas = 'silver' THEN 9
WHEN attendance_clas = 'silver' THEN 10
WHEN slots_clas = 'silver' THEN 11
WHEN orders_clas = 'silver'THEN 12
WHEN hdh_clas = 'silver' THEN 13
WHEN rating_clas = 'silver' THEN 14
WHEN acceptance_clas = 'diamond' THEN 15
WHEN completion_clas = 'diamond' THEN 16
WHEN attendance_clas = 'diamond' THEN 17
WHEN slots_clas = 'diamond' THEN 18
WHEN orders_clas = 'diamond'THEN 19
WHEN hdh_clas = 'diamond' THEN 20
WHEN rating_clas = 'diamond' THEN 21
ELSE null END AS classification_metrics
FROM uy_writable.performance_new
WHERE cycle_order = 1
)
, temp_table2 AS(
SELECT country, storekeeper_id, level_name
FROM uy_writable.performance_new
)
SELECT a.country, a.storekeeper_id, a.level_name, MIN(b.classification_metrics)
FROM temp_table2 AS a
LEFT JOIN temp_table AS b ON a.storekeeper_id = b.rt_id



AL MOMENTO DE CORRERLO ME DICE. SQL compilation error: [A.COUNTRY] is not a valid group by expression
NO SE POR QUÉ
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de gilman
Val: 184
Ha mantenido su posición en SQL (en relación al último mes)
Gráfica de SQL

SQL join

Publicado por gilman (103 intervenciones) el 13/12/2021 09:50:14
estás usando MIN(b.classification_metrics), la función MIN es una función de agrupado, y cuando se usa una función de agrupado el resto de campos debería estar en la cláusula GROUP BY
La última sentencia debería quedar:
1
2
3
4
SELECT a.country, a.storekeeper_id, a.level_name, MIN(b.classification_metrics)
FROM temp_table2 AS a
LEFT JOIN temp_table AS b ON a.storekeeper_id = b.rt_id
GROUP BY  a.country, a.storekeeper_id, a.level_name
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar