用户数量/等级之间的数量
我想返回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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢 aynber ,和 Honk der Hase 。为了帮助我理解自己的错误并为我提供解决方案。因此,如果其他任何人都遇到了这个问题,则修复程序是:
将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:
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.
首先,正如各个人所说的那样,您的查询是错误的
,您有不同的方法来完成范围检查。我将显示其中的3个...
首先:
这将是进行检查的最兼容的方法(对于SQL查询),这可能是任何数据库支持的,因为它仅使用基本的concarsion操作。
第二:
尽管如今得到了广泛的支持,但两者之间是一个特殊的关键字,所有数据库系统可能并不知道。
第三:
虽然这是完全有效的,但它适合范围有空白的情况。 (例如“ 11至24,但除17”)
First, your query is faulty
As said by various people, you have different ways to accomplish a range check. I'll show 3 of them...
First:
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:
Though nowadays broadly supported, BETWEEN is a special keyword which might not be known by all database system.
Third:
While this is perfectly valid, it fits better to cases when the range has gaps. (like "11 to 24, but except 17")