dongse5408 2015-06-02 16:31
浏览 24
已采纳

SQL,检查表中所有记录的值是否大于5 [关闭]

I am using PHP and I need a sql query which will check whether all records value greater then 5.. Won't return any data from database. Just will return true if all records are greater then 5.

If the answer is true I will update another table..

Pseudo Code is

if(the value column in table1 is greater then 5 for all records)
then
    $update = mysql_query("UPDATE table2 SET q_value = '0' ")
else
do nothing


Table Example:
------------------------

| question |  value   |
|    X1    |     6    |
|    X2    |     6    |
|    X3    |     6    | //value column for all records are greater then 5 
|    X4    |     7    | //must return true
|    X5    |     8    | //and will update table2
|    X6    |     6    |

| question |  value   |
|    X1    |     6    |
|    X2    |     3    |
|    X3    |     0    | //value column for all records not greater then 5 
|    X4    |     7    | //there are 0 and 3 values and must return false
|    X5    |     8    | //won't update table2 
|    X6    |     6    |

Could you please give me an idea for this. How can I check something for all records. Won't return any data. Just will return true if all values greater then something...

Thank you in advance

  • 写回答

1条回答 默认 最新

  • doutuo6689 2015-06-02 16:42
    关注
    select count(*)
    from table1
    where value <= 5
    

    If 0 is returned, it's TRUE, FALSE otherwise.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像