如何获取mysql数据库的行数
+-------------------+---------------------+------+-----+---------+----------------+
| RowId | MSGID| Received| UID | Default | |
+-------------------+---------------------+------+-----+---------+----------------+
| 1 | 1 | NO | 1 | NULL | |
| 2 | 1 | YES | 3 | NULL | |
| 3 | 1 | YES | 4 | NULL | |
| 4 | 1 | YES | 5 | NULL | |
| 5 | 5 | YES | 2 | NULL | |
| 6 | 2 | YES | 8 | NULL | |
| 7 | 1 | YES | 9 | NULL | |
+-------------------+---------------------+------+-----+---------+----------------+
这是我在 MySQL 中的表。
如何获取 MSGID = 1
的消息计数以及已收到 MSGID = 1
消息的用户数量以及未收到消息的用户数量消息 MSGID = 1
?
我想在循环中执行此操作,以便可以获得 [5,4,1] 等三个值。因此,每次页面加载时,查询都会检查数据库并更新集合。请帮忙
+-------------------+---------------------+------+-----+---------+----------------+
| RowId | MSGID| Received| UID | Default | |
+-------------------+---------------------+------+-----+---------+----------------+
| 1 | 1 | NO | 1 | NULL | |
| 2 | 1 | YES | 3 | NULL | |
| 3 | 1 | YES | 4 | NULL | |
| 4 | 1 | YES | 5 | NULL | |
| 5 | 5 | YES | 2 | NULL | |
| 6 | 2 | YES | 8 | NULL | |
| 7 | 1 | YES | 9 | NULL | |
+-------------------+---------------------+------+-----+---------+----------------+
This is my table in MySQL.
How can I get count of messages where MSGID = 1
and count of no of users who have received message where MSGID = 1
and count of no of users who haven't received message where MSGID = 1
?
I want to do it in a loop so that I can Get three values like [5,4,1]. So each time the page load the query will check the database and update the sets. pls help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先获取消息数量计数,其中 MSGID = 1
获取已收到消息的用户数量计数,其中 MSGID = 1
获取未收到消息的用户数量计数,其中 MSGID = 1
First to get a count for the number of messages where MSGID = 1
To get a count of the number of users who have received a msg where MSGID = 1
To get a count of the number of users who haven't received a msg where MSGID = 1
您可以在一个查询中完成此操作。我没有看到循环的好处?
这实际上应该是多个表,
1)用户,在 uid 上不同
2)消息,在 msgid 上不同,收到的是/否。
You can do this in one query. I don't see the benefit of the loop?
This should really be multiple tables,
1) users, distinct on uid
2) messages, distinct on msgid, with received yes / no.
要使用一个查询来获取它,您可以像下面这样进行联合:
希望这对您有用。
To get it using one query you can do a union all like the following:
Hope this works out for you.