sql >> Database teknologi >  >> RDS >> Mysql

Brug korreleret underforespørgsel over flere kolonner

Du kan bruge en underforespørgsel og gruppere data efter kampagne:

SELECT campaign,MAX(event_type) AS event_type,
CASE WHEN MAX(sub_event_date)>MAX(main_event_date) THEN MAX(sub_event_date) ELSE MAX(main_event_date) END  AS event_date,
CASE WHEN MAX(sub_event_date)>MAX(main_event_date) THEN MAX(sub_event_quantity) ELSE MAX(main_event_quantity) END AS event_quantity
FROM (
SELECT 
campaign,
event_type,
coalesce(date_offered, date_ordered) as main_event_date,
coalesce(date_delivered, date_recorded, date_completed) as sub_event_date,
coalesce(quantity_offered, quantity_ordered) as main_event_quantity,
coalesce(quantity_delivered, quantity_recorded, quantity_completed) as sub_event_quantity
FROM logistics lg) l
GROUP BY campaign


  1. hvordan fjerner man omvendt skråstreg (\) i json-svaret ved hjælp af php?

  2. Hvordan lader man en bruger indsætte hvor som helst på en liste?

  3. PHP-script til at logge de rå data fra POST

  4. Hashing eller kryptering af variabler, der skal sendes i en url