MySQL条件

发布于 2024-09-11 13:18:02 字数 365 浏览 0 评论 0原文

我对 MySQL 还很陌生,我不知道最好的方法。

我有一个包含递增值的表,如果这些值超过某个限制,我想知道。假设我有一个带有 current 列和 capacity 列的表。 current 中的一行根据用户输入递增,我想知道 current 行中的值何时超过或满足其相应的capacity

如果当前仍然低于容量,我希望查询返回true。但是,如果 current 满足或超过 capacity,我希望查询返回 false。

谢谢!

I'm still pretty new with MySQL and I don't know the best way to do this.

I have a table with incremented values, and if the values exceed a certain limit, I'd like to know. So lets say I have this table with a current column and capacity column. A row in current is incremented by user input and I want to know when the value in a current row exceeds or meets its corresponding capacity.

If current is still below the capacity, I would like the query to return true. However, if current meets or exceeds capacity, I would like the query to return false.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

盛夏已如深秋| 2024-09-18 13:18:02

在 mysql 中这很简单:

select (current >= capacity) as exceeded from table

in mysql that's easy:

select (current >= capacity) as exceeded from table
失退 2024-09-18 13:18:02

添加一个 WHERE 子句来检查您的 UPDATE 查询:

// I assume you mean you want to increment the current column by 1,
// but it's your table so change the SET values as needed
$updated = mysql_query('UPDATE table SET current = current + 1 WHERE id = ' . intval($row_id) . ' AND current < capacity');

然后检查 UPDATE 查询的 mysql_affected_rows() :

if (mysql_affected_rows() > 0)
{
    // Success
}

Add a WHERE clause to do that check in your UPDATE query:

// I assume you mean you want to increment the current column by 1,
// but it's your table so change the SET values as needed
$updated = mysql_query('UPDATE table SET current = current + 1 WHERE id = ' . intval($row_id) . ' AND current < capacity');

Then check mysql_affected_rows() of the UPDATE query:

if (mysql_affected_rows() > 0)
{
    // Success
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文