哪个条款没有遵守

时间:2016-12-27 20:28:27

标签: php mysql sql

我在网上找到了以下sql查询,如果它正常工作,那将是完美的,但它并没有遵守where子句。

SELECT *
FROM Chicken AS a,
     (SELECT MIN(Temp) AS mini, MAX(Temp) AS maxi
      FROM Chicken
     ) AS m
WHERE m.maxi = a.Temp AND `Location` = "Outside" OR m.mini = a.Temp AND `Location` = "Outside"
ORDER BY `a`.`Time` DESC Limit 1

正在发生的事情是它无论位置如何都采取最低和最高温度。我需要它来找到该位置的最低和最高温度'外部'

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

SELECT *
FROM Chicken AS a,
     (SELECT MIN(Temp) AS mini, MAX(Temp) AS maxi
      FROM Chicken
     ) AS m
WHERE (m.maxi = a.Temp AND `Location` = "Outside") OR (m.mini = a.Temp AND `Location` = "Outside")
ORDER BY `a`.`Time` DESC Limit 1

试试这可能适合你。