我正在使用PHP,我需要一个sql查询,它将检查所有记录的值是否大于5 ..不会从数据库返回任何数据。如果所有记录都大于5,则返回true。
如果答案是真的,我会更新另一张表..
伪代码是
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 |
你能告诉我这个想法吗?如何检查所有记录的内容。不会返回任何数据。如果所有值都大于某个值,则返回true ...
提前谢谢
答案 0 :(得分:1)
select count(*)
from table1
where value <= 5
如果返回0,则为TRUE,否则为FALSE。