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

Multiple forespørgsler Output i enkelt tabel

Jeg kan råde dig til at bruge enkelt forespørgsel:

SELECT 
    Entity_Name,
    Count(*) Count_All,
    Count(NULLIF(Plan_Name, 'Complementary_Package')) Not_Complementary_Package
FROM mq_active_sep21 
GROUP BY Entity_Name 
ORDER BY Entity_Name;

og kode som:

$sql = mysqli_query($connection, "
    SELECT 
        Entity_Name,
        Count(*) Count_All,
        Count(NULLIF(Plan_Name, 'Complementary_Package')) Not_Complementary_Package
    FROM mq_active_sep21 
    GROUP BY Entity_Name 
    ORDER BY Entity_Name;
");

while($row = mysqli_fetch_assoc($sql)) {
    printf(
        "Entity_Name: %s, Total: %d, Complementary_Package: %d " . PHP_EOL, 
        $row['Entity_Name'],
        $row['Count_All'],
        $row['Count_All'] - $row['Not_Complementary_Package']
    );
}

  1. Hvordan opretter jeg en bruger med de samme rettigheder som root i MySQL/MariaDB?

  2. SQL opdatering top1 række forespørgsel

  3. MySQL-understøttelse af Python, der ikke er under GPL-lignende licenser

  4. Angiv tabeltypen/lagringsmotoren i Doktrin 2