sql >> データベース >  >> RDS >> Mysql

3つのSQLクエリを組み合わせる

    これはあなたのために働くかもしれません。

    SElECT COUNT(*) AS imgCount FROM (
        SELECT imgHeight, imgWidth, imgId AS primaryId FROM primary_images
        UNION ALL 
        SELECT imgHeight, imgWidth, primaryId FROM secondary_images
    ) AS union_table
    WHERE primaryId = $imgId 
    AND (imgWidth != $maxImageWidth AND imgHeight = $maxImageHeight
    OR imgWidth = $maxImageWidth AND imgHeight != $maxImageHeight
    OR imgWidth = $maxImageWidth AND imgHeight = $maxImageHeight);
    

    よくわかりませんが、これも同等だと思います。

    SElECT COUNT(*) AS imgCount FROM (
        SELECT imgHeight, imgWidth, imgId AS primaryId FROM primary_images
        UNION ALL 
        SELECT imgHeight, imgWidth, primaryId FROM secondary_images
    ) AS union_table
    WHERE primaryId = $imgId 
    AND (imgWidth = $maxImageWidth OR imgHeight = $maxImageHeight);
    

    リクエストに従って、3行を返す単一のクエリがあります。

    SELECT 'ALL EQUAL' AS COL1,COUNT(*) AS imgCount FROM (
        SELECT imgHeight, imgWidth, imgId AS primaryId FROM primary_images
        UNION ALL 
        SELECT imgHeight, imgWidth, primaryId FROM secondary_images
    ) AS union_table
    WHERE primaryId = $imgId AND imgWidth = $maxImageWidth AND imgHeight = $maxImageHeight
    UNION ALL
    SELECT 'WIDTH EQUAL' AS COL1,COUNT(*) AS imgCount FROM (
        SELECT imgHeight, imgWidth, imgId AS primaryId FROM primary_images
        UNION ALL 
        SELECT imgHeight, imgWidth, primaryId FROM secondary_images
    ) AS union_table
    WHERE primaryId = $imgId AND imgWidth = $maxImageWidth AND imgHeight != $maxImageHeight;
    UNION ALL
    SELECT 'HEIGHT EQUAL' AS COL1,COUNT(*) AS imgCount FROM (
        SELECT imgHeight, imgWidth, imgId AS primaryId FROM primary_images  
        UNION ALL 
        SELECT imgHeight, imgWidth, primaryId FROM secondary_images
    ) AS union_table
    WHERE primaryId = $imgId AND imgWidth != $maxImageWidth AND imgHeight = $maxImageHeight;
    


    1. MySQLジョブを開始できませんでした

    2. Oracleパスワードの有効期限をオフにするにはどうすればよいですか?

    3. データをデコードしようとしています(AbsをMySQLにエクスポートします)

    4. PDOはローカルホスト(不明なmysqlサーバーホスト)に接続します