gpt4 book ai didi

mysql - 查询连接上的最大值

转载 作者:行者123 更新时间:2023-11-29 08:48:59 25 4
gpt4 key购买 nike

如何获取 max MESSAGENUMBER

mysql> 
mysql> describe ARTICLE;describeNEWSGROUP;
+---------------+------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+------------+------+-----+---------+----------------+
| ID | bigint(20) | NO | PRI | NULL | auto_increment |
| MESSAGENUMBER | int(11) | YES | | NULL | |
| NEWSGROUP_ID | bigint(20) | YES | MUL | NULL | |
+---------------+------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

+-----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+----------------+
| ID | bigint(20) | NO | PRI | NULL | auto_increment |
| NEWSGROUP | varchar(255) | YES | | NULL | |
+-----------+--------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

mysql>
mysql> select * from ARTICLE left join NEWSGROUP on ARTICLE.NEWSGROUP_ID=NEWSGROUP.ID where NEWSGROUP.newsgroup = "gwene.com.economist";
+----+---------------+--------------+------+---------------------+
| ID | MESSAGENUMBER | NEWSGROUP_ID | ID | NEWSGROUP |
+----+---------------+--------------+------+---------------------+
| 18 | 4 | 4 | 4 | gwene.com.economist |
| 19 | 5 | 4 | 4 | gwene.com.economist |
| 20 | 6 | 4 | 4 | gwene.com.economist |
| 21 | 7 | 4 | 4 | gwene.com.economist |
| 22 | 8 | 4 | 4 | gwene.com.economist |
| 23 | 9 | 4 | 4 | gwene.com.economist |
| 24 | 10 | 4 | 4 | gwene.com.economist |
| 25 | 11 | 4 | 4 | gwene.com.economist |
+----+---------------+--------------+------+---------------------+
8 rows in set (0.00 sec)

mysql>

最佳答案

SELECT MAX(MESSAGENUMBER)
FROM ARTICLE left join NEWSGROUP on ARTICLE.NEWSGROUP_ID=NEWSGROUP.ID
WHERE NEWSGROUP.newsgroup = "gwene.com.economist"

关于mysql - 查询连接上的最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11807439/

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