Ver Mensaje Individual
  #4 (permalink)  
Antiguo 16/01/2020, 11:02
antonio_dsanchez
 
Fecha de Ingreso: abril-2015
Mensajes: 130
Antigüedad: 9 años
Puntos: 0
Respuesta: Crear una ciclo de analisis de datos en sql

creo que ya lo tengo

Código SQL:
Ver original
  1. SELECT
  2.  
  3. A1.PO_No,A7.Name,A1.Supplier_No,A5.Supplier_Code,A2.Line_Item_No,
  4. A3.Item_No,A3.Description,A2.Unit_Price,A2.Unit,A1.Currency_Code,
  5. A4.Supplier_No,A6.Supplier_Code,
  6. A4.Unit_Price,A4.Lead_Time,
  7.  
  8. CASE
  9. WHEN A2.Unit_Price > (SELECT MIN( Unit_Price) FROM Purchasing_v_Item_Supplier_Price_e
  10. WHERE Item_Key = A2.Item_Key)  THEN 'EXISTE UN MEJOR PRECIO'
  11. WHEN A2.Unit_Price <= (SELECT MIN( Unit_Price) FROM Purchasing_v_Item_Supplier_Price_e
  12. WHERE Item_Key = A2.Item_Key) THEN 'NO'
  13. END,
  14. (SELECT MIN( Unit_Price) FROM Purchasing_v_Item_Supplier_Price_e
  15. WHERE Item_Key = A2.Item_Key)
  16.  
  17.  
  18. FROM Purchasing_v_PO_e A1
  19. INNER JOIN Purchasing_v_Line_Item_e A2 ON A1.PO_Key = A2.PO_Key
  20. INNER JOIN Purchasing_v_Item_e A3 ON A3.Item_Key = A2.Item_Key
  21. INNER JOIN Purchasing_v_Item_Supplier_Price_e A4 ON A4.Item_Key = A2.Item_Key
  22. LEFT JOIN Common_v_Supplier_e A5 ON A5.Supplier_No =  A1.Supplier_No
  23. LEFT JOIN Common_v_Supplier_e A6 ON A6.Supplier_No =  A4.Supplier_No
  24. LEFT JOIN Common_v_Department_e A7 ON A7.Department_No = A1.Department_No
  25. WHERE A7.Name = 'Produccion'

lo pueden revisar y comentar