用户数量/等级之间的数量

发布于 2025-01-28 07:45:34 字数 449 浏览 2 评论 0原文

我想返回X成员/用户的数量,其等级为1-10、11-24,另一个从25-35开始。两个用户都在NCO类别中出现。即使一个用户是排名27,而另一个用户是排名13?我尝试用这些符号弄乱,将其更改为Just< or>或==,但仍然没有遇到任何用户出现的用户。

$stats['afenlisted'] = $pdo->query('SELECT count(*) from personnel WHERE rank >= "25" AND branch = "Air Force" ')->fetchColumn();

$stats['afnco'] = $pdo->query('SELECT count(*) from personnel WHERE rank >= "11" <= "24" AND branch = "Air Force" ')->fetchColumn();

I want to return x amount of members/users with a rank from 1-10, 11-24, and another from 25-35. Both users keep showing up in the NCO category. Even when one user is rank 27 and another is rank 13? I have tried messing with the symbols, changing it to just < or > or == but still run into no user showing up to both users showing up.

$stats['afenlisted'] = $pdo->query('SELECT count(*) from personnel WHERE rank >= "25" AND branch = "Air Force" ')->fetchColumn();

$stats['afnco'] = $pdo->query('SELECT count(*) from personnel WHERE rank >= "11" <= "24" AND branch = "Air Force" ')->fetchColumn();

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

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

发布评论

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

评论(2

故事还在继续 2025-02-04 07:45:34

感谢 aynber Honk der Hase 。为了帮助我理解自己的错误并为我提供解决方案。因此,如果其他任何人都遇到了这个问题,则修复程序是:

$stats['afenlisted'] = $pdo->query('SELECT count(*) from personnel WHERE rank BETWEEN 25 AND 28 AND branch = "Air Force" ')->fetchColumn();

#For your own code something like this:

$stats['Whatever you want to call it'] = $pdo->query('SELECT count(*) FROM your table name WHERE column BETWEEN x AND y AND if you have another column your trying to get from ')->fetchColumn();

将x和y更改为您想要的任何数字,如果您没有其他列要获得更多的东西,请删除y(然后删除y(您的数字价值)

再次感谢那些家伙帮助我了解自己的错误,并了解有关SQL东西的更多信息。

Thanks to Aynber, AbraCadaver, and Honk der Hase. For helping me understand my mistake and getting me the fix for it. So if anyone else is running into this issue, the fix is:

$stats['afenlisted'] = $pdo->query('SELECT count(*) from personnel WHERE rank BETWEEN 25 AND 28 AND branch = "Air Force" ')->fetchColumn();

#For your own code something like this:

$stats['Whatever you want to call it'] = $pdo->query('SELECT count(*) FROM your table name WHERE column BETWEEN x AND y AND if you have another column your trying to get from ')->fetchColumn();

Change the x AND y to whatever number you want, if you don't have another column you're trying to get more stuff for then just remove the AND after y (your number value)

Thanks again to those guys for helping me understand my mistakes and learning more about SQL stuff.

等待我真够勒 2025-02-04 07:45:34

首先,正如各个人所说的那样,您的查询是错误的

$stats['afnco'] = $pdo->query('SELECT count(*) from personnel WHERE rank >= "11" <= "24" AND branch = "Air Force" ')->fetchColumn();

,您有不同的方法来完成范围检查。我将显示其中的3个...

首先:

SELECT .. FROM .. WHERE rank >= 11 AND rank <= 24

这将是进行检查的最兼容的方法(对于SQL查询),这可能是任何数据库支持的,因为它仅使用基本的concarsion操作。

第二:

SELECT .. FROM .. WHERE rank BETWEEN 11 and 24

尽管如今得到了广泛的支持,但两者之间是一个特殊的关键字,所有数据库系统可能并不知道。

第三:

SELECT .. FROM .. WHERE rank IN(11,12,13,14,15,16,17,18,19,20,21,22,22,23,24)

虽然这是完全有效的,但它适合范围有空白的情况。 (例如“ 11至24,但除17”)

First, your query is faulty

$stats['afnco'] = $pdo->query('SELECT count(*) from personnel WHERE rank >= "11" <= "24" AND branch = "Air Force" ')->fetchColumn();

As said by various people, you have different ways to accomplish a range check. I'll show 3 of them...

First:

SELECT .. FROM .. WHERE rank >= 11 AND rank <= 24

This would be the most compatible way (for SQL queries) to do the check, probably supported by the any database out there, as it uses only basic comparsion operations.

Second:

SELECT .. FROM .. WHERE rank BETWEEN 11 and 24

Though nowadays broadly supported, BETWEEN is a special keyword which might not be known by all database system.

Third:

SELECT .. FROM .. WHERE rank IN(11,12,13,14,15,16,17,18,19,20,21,22,22,23,24)

While this is perfectly valid, it fits better to cases when the range has gaps. (like "11 to 24, but except 17")

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