gpt4 book ai didi

MySQL 复杂查询(分组依据)

转载 作者:行者123 更新时间:2023-11-30 22:07:52 24 4
gpt4 key购买 nike

下面是我的查询:

SELECT date, eventype, count(*) AS count 
FROM vpnhistory WHERE partnername REGEXP 'CESAR'
GROUP BY (UNIX_TIMESTAMP(date)) DIV 600;

我得到的:

+---------------------+--------------+---------+
| date | eventype | counter |
+---------------------+--------------+---------+
| 2016-09-30 12:42:41 | blocked | 4 |
| 2016-10-03 10:55:55 | blocked | 1 |
| 2016-10-03 13:43:01 | blocked | 1 |
| 2016-10-04 15:17:19 | blocked | 2 |
| 2016-10-04 15:21:03 | blocked | 3 |

这是 CESAR 合作伙伴名称收到的总事件类型。

我的 SELECT * FROM vpnhistory 是:

+----------------------+---------------------+--------------+-------------+
| vpnname | date | eventype | partnername |
+----------------------+---------------------+--------------+-------------+
| treinamento-12345678 | 2016-09-30 12:42:41 | blocked | CESAR |
| treinamento-45263748 | 2016-09-30 12:43:53 | unlock | CESAR |
| treinamento-92837465 | 2016-09-30 12:46:50 | unlock | CESAR |
| treinamento-92837465 | 2016-09-30 12:46:50 | unlock | CESAR |
| treinamento-92837465 | 2016-09-30 12:46:50 | unlock | CESAR |
+----------------------+---------------------+--------------+-------------+

我需要的例子:

How many eventype treinamento-92837465 exists? (inside partnername CESAR)
How many eventype treinamento-12345678 exists? (inside partnername CESAR)

最佳答案

SELECT date, eventtype, count(*)
FROM vpnhistory WHERE partnername REGEXP 'CESAR'
GROUP BY date, eventtype

这是你想要的吗?我不明白你的第一个 group by 子句。

关于MySQL 复杂查询(分组依据),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41061372/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com