Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

Gabung dalam dengan pernyataan if, grup

saya masih tidak yakin apa yang Anda inginkan.

sesuatu seperti ini?

WITH group2 AS (

    SELECT r.Restaurant_ID, r.Name, f.Feature
    FROM   Restaurants r
    INNER JOIN Bridge1_Restaurant_Features b ON b.Restaurant_ID = r.Restaurant_ID
    INNER JOIN Features f ON b.Feature_ID = f.Feature_ID
    INNER JOIN
    (
         SELECT Restaurant_ID, COUNT(Feature_ID) AS FeatureCount
         FROM   Bridge1_Restaurant_Features
         <!--- find matching features --->
         WHERE  Feature_ID IN ( <cfqueryparam value="#ARGUMENTS.Feature_ID#"   cfsqltype="cf_sql_integer" list="true"> )
        GROUP BY Restaurant_ID
        <!--- having ALL of the requested features --->
         HAVING COUNT(Feature_ID) = <cfqueryparam value="#listLen(ARGUMENTS.Feature_ID)#" cfsqltype="cf_sql_integer">
        ) ck ON ck.Restaurant_ID = r.Restaurant_Id

)

SELECT r.Name , r.Restaurant_ID, f.feature, r.Price_Range, r.Cuisine_ID, c.Cuisine,
    s.State_ID, s.State, l.Location_ID, l.Area, l.State_ID, r.Name, r.Location_ID
FROM Restaurants r, Bridge1_Restaurant_Features b, Features f, Cuisine c, State s, Location l
    where 0=0
    AND b.Feature_ID = f.Feature_ID 
    AND b.Restaurant_ID = r.Restaurant_ID
    AND r.Cuisine_ID = c.Cuisine_ID 
    AND r.Location_ID = l.Location_ID
    AND l.State_ID = s.State_ID
    <cfif ARGUMENTS.Feature_ID IS NOT "">
    AND f.Feature_ID IN (group2.Restaurant_ID)
    </cfif>
    <cfif ARGUMENTS.Price_Range IS NOT "">
    AND r.Price_Range IN (#ARGUMENTS.Price_Range#)
    </cfif>
    <cfif ARGUMENTS.Cuisine IS NOT "">
    AND r.Cuisine_ID = (#ARGUMENTS.Cuisine#)
    </cfif>
    <cfif val(ARGUMENTS.LocationID2) IS #val(ARGUMENTS.StateID)#>
    AND l.State_ID = #val(ARGUMENTS.LocationID2)#
    <cfelse>
        AND l.Location_ID = #val(ARGUMENTS.LocationID2)#
    </cfif>


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Mysql menampilkan baris sebagai kolom

  2. (perlu saran) Bicara ke database server MySQL dari Aplikasi Android saya

  3. StaleObjectStateException pada pembaruan frekuensi tinggi

  4. Oracle MERGE dan pernyataan yang disiapkan

  5. while ($row =mysql_fetch_array($result)) - berapa banyak loop yang dilakukan?