加入两个表并查看极值 - 无法正常查询

时间:2013-11-25 14:28:42

标签: php mysql

我有两个表我加入两个表,并希望显示选择一列的极值,这是php / mysql代码。

$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   ";

当回显查询;首先我选择$ year = 2008 $ month = 2和$ parameter = soil_temp_60和$ 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 ;

与此查询相关的表中的极值但效果不佳

1 个答案:

答案 0 :(得分:0)

我认为你的问题是错误的地方,试试这个:

$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 ";