dtra49684 2012-01-26 20:15
浏览 125
已采纳

创建一个SQL语句,通过比较一行中的两个字段来查询MySQL数据库

I have a table as example below:

Prices

ID*low*high**value

1*1*4**29.0

2*5*9**32.0

3*10*25**50.0

low and high are both INT

I've tried: $SQL = "SELECT value from Prices WHERE low >= '2' AND high <= '2' but I come up with zero (0) results returned where in this example I'm wanting to find 29.0

edited my table above as it was unclear after I saw it formated.

  • 写回答

2条回答 默认 最新

  • dongyouji7022 2012-01-26 20:16
    关注

    I cannot see a high <= 2 in your example above. You might wanna review that.

    $SQL = "SELECT value from Prices WHERE low >= '2' AND high <= '2'"

    The above code you showed us is correct.

    I believe you want it switched around to find value 29.0:

    $SQL = "SELECT value from Prices WHERE low <= '2' AND high >= '2'"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?