Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在 MYSQL 中编写以下内容?
SELECT AVG(col1) FROM table WHERE DISTINCT col2
更多信息:
table col1 | col2 ----------- 2 | 555.555.555.555 5 | 555.555.555.555 4 | 444.444.444.444
返回“3”
基本上我试图选择col1的平均值,其中col2中的IP 地址是不同的。
SELECT col2, AVG(col1) FROM table GROUP BY col2
对,因为 distinct 子句会找到第一行和第三行,所以 2 和 4 的平均值是 3。
我认为您正在寻找的是“按 col2 分组”而不是不同的。
我想你想要group by运营商。它将在对它们运行计算之前对行进行分组。
group by