简体   繁体   中英

Joining two table and view extreme values - not work query properly

i have two table i joining both tables and want display extreme values of select one columns this is php/mysql code.

$sql="Select A.date, A.rainfall, A.evep , 
             A.max_temp , A.min_temp , A.sunshine_hrs , 
             B.temp_air , B.dry_temp ,B.wet_temp,
             B.rel_humid , B.soil_temp_5, B.soil_temp_20,
             B.soil_temp_30 , B.soil_temp_60 , 
             B.air_pressure 
        FROM reg_data3 A 
                 INNER JOIN reg_data2 B 
                   ON A.date = B.date 
       WHERE year(DATE_FORMAT(A.date, '%y-%m-%d'))='".$year."' 
         and month(DATE_FORMAT(A.date, '%y-%m-%d'))='".$month."'  
       ORDER BY B.date and $paramiter > $value   ";

when echo query; first i select $year=2008 $month=2 and $parameter=soil_temp_60 and $value=20

Select A.date, A.rainfall, A.evep , A.max_temp , 
       A.min_temp , A.sunshine_hrs , B.temp_air , 
       B.dry_temp ,B.wet_temp, B.rel_humid , 
       B.soil_temp_5 ,B.soil_temp_20 , B.soil_temp_30 , 
       B.soil_temp_60 , B.air_pressure 
  FROM reg_data3 A 
          INNER JOIN reg_data2 B 
            ON A.date = B.date 
 WHERE year(DATE_FORMAT(A.date, '%y-%m-%d'))='2008' 
   and month(DATE_FORMAT(A.date, '%y-%m-%d'))='02' 
 ORDER BY B.date and A.soil_temp_60 > 24 ;

extreme values in table related to this query but not work well

I think that your problem is with variables in wrong place, try this:

$sql="Select A.date, A.rainfall, A.evep , 
         A.max_temp , A.min_temp , A.sunshine_hrs , 
         B.temp_air , B.dry_temp ,B.wet_temp,
         B.rel_humid , B.soil_temp_5, B.soil_temp_20,
         B.soil_temp_30 , B.soil_temp_60 , 
         B.air_pressure 
    FROM reg_data3 A 
             INNER JOIN reg_data2 B 
               ON A.date = B.date 
   WHERE year(DATE_FORMAT(A.date, '%y-%m-%d'))='".$year."' 
     and month(DATE_FORMAT(A.date, '%y-%m-%d'))='".$month."'  
     and $paramiter > $value 
   ORDER BY B.date ";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM