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

Sådan håndterer du store mysql-forespørgsler

Jeg tror, ​​at alle de korrelerede underforespørgsler dræber dig. Prøv dette:

SELECT  p2c.pid AS productNumber,
        p.name AS productName,
        COUNT(*) AS registered,
        SUM(date_add(from_unixtime(purchased), INTERVAL 5 YEAR) >= CURDATE()) AS inWarranty,
        SUM(date_add(from_unixtime(purchased), INTERVAL 5 YEAR) < CURDATE()) AS outOfWarranty,
        DATE_FORMAT( MAX( from_unixtime(purchased) ), '%d.%m.%Y') AS lastPurchased,
        DATE_FORMAT( date_add( MAX( from_unixtime(purchased) ), INTERVAL 5 YEAR), '%d.%m.%Y') AS warrantyUntil
FROM products2customers p2c
JOIN products p ON p.id = p2c.pid
GROUP BY p2c.pid
ORDER BY inWarranty DESC


  1. Viser oracle-appen og får:java.lang.ClassNotFoundException:oracle.forms.engine.Main

  2. Hvordan opretter man forbindelse til Cloud SQL MySQL-database fra App Engine?

  3. forskel mellem localhost og postgres for vært i docker

  4. Sammenligning af objekter efter værdi. Del 6:Struktur ligestillingsimplementering