mysql 更新为最大值,更新数据库中的最大值php mysql的列

I got problem here. im updating name where B has the biggest value.

so the results are

B | name

---|------

1 |

2 |

3 | YES

but when column B changes value the problem is column name with row value 3 still has a value.

B | name

---|------

1 |

4 | YES

3 | YES

the results should be.

B | name

---|------

1 |

4 | YES

3 |

if

B | name

---|------

0 |

0 |

0 |

then

B | name

---|------

0 |

0 |

0 |

if,

B | name

---|------

4 |

4 |

2 |

then

B | name

---|------

4 | YES

4 | YES

2 |

this is what i want.

im only using this simple code.

$sql3 = "UPDATE products SET name='YES' ORDER BY B DESC";

解决方案

I think you want to update the row in the the table where column B is the highest value? You definitely need a "WHERE" clause, but you also need to know the highest value in that column. Why don't you query the database first to retrieve the highest value from column B?

$maxvalue = "SELECT `B` FROM products ORDER BY `B` DESC LIMIT 1"

and then insert into the database WHERE the column B equals this value?

"UPDATE products SET name='YES' WHERE B = $maxvalue"

This is not complete code, just conceptual. I will clean it up and edit this answer...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值