mysql 计数函数
我感兴趣的是,如果我想计算表(mysql 数据库)中的某些列,其中必须在另一个查询中选择该列,如何编写 mysql 查询? 像这样 从表中选择 COUNT(OTHER_QUERY)
我有一个名为 port 的列,并且希望在另一个查询中计算此列,如下所示(选择 port='GCP' 的端口;
我正在尝试执行此任务,但使用没有结果(尽管有帮助) 我是这样写的 => SELECT COUNT(port) from data WHERE port =(从数据中选择端口,其中 port='GCP')
所以我想计算等于 GCP 的列端口,
请帮助完成这项任务:)
I'm interested in how I can write mysql query if I want to count some column from table (mysql database) where that column must be chosen within another query ?
like thisSELECT COUNT(OTHER_QUERY) FROM TABLE
I have column named port and want to count this column within another query like this (select port where port='GCP';
I'm trying to do this task but with no result (despite of helping)
I'm writing like so =>SELECT COUNT(port) from data WHERE port = (select port from data where port='GCP')
So I want to count column port which are equal to GCP
please help with this task :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需将原始查询包装在子选择中:
对于您的第二个查询,我相信这应该得到您想要的:
Just wrap the original query in a sub-select:
For your second query, I believe this should get what you want:
它将如下所示:
It will be like below :
你想要这样的东西吗:
想要端口总数(如果它的值是GCP)。
如果是这样,则语法如下:
SELECT COUNT(port) AS alias WHERE port = GCP;
你可能会发现这个 MySQL COUNT 个有用的资源。
Do you want something like this :
Want total number of ports if it's value is GCP.
If so, then this is the syntax:
SELECT COUNT(port) AS alias WHERE port = GCP;
You may find this MySQL COUNT resources useful.