mysql查询不等于列数据的数据

5ssjco0h  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(386)

我在mysql中使用这个结构

SET FOREIGN_KEY_CHECKS=0;
DROP TABLE IF EXISTS `statistics`;
CREATE TABLE `statistics` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user` int(255) DEFAULT NULL,
  `machine_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `os_structure` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `os_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `os_version` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `processor_count` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `version` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ip` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `country` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `country_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `date` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPRESSED;

目前的问题是:

SELECT `os_name`, `os_structure`, COUNT(*) AS `count` FROM `statistics` GROUP BY `os_name`, `os_structure` ORDER BY `count` DESC;

我的问题是如何得到数据,但不是从同一个数据 ip 上的列 count 结果,由于我不是统计Maven,任何改进都是值得欢迎的。以下是 os_name , os_structure , count 真/假结果等于64位系统(表示真)或32位系统(表示假)。当我尝试按ip分组时,结果比预期的要多很多次 windows 7 professional 这不是我想要的。

Microsoft Windows 7 Professional    True    36
Microsoft Windows 10 Pro            True    26
Microsoft Windows 7 Ultimate        False   12
Microsoft Windows 7 Professional    False   11
Microsoft Windows 7 Ultimate        True    5
Microsoft Windows 7 Enterprise      False   1
Microsoft Windows 7 Professional N  True    1
Microsoft Windows 7 Ultimate K      False   1
daolsyd0

daolsyd01#

也许是一个计数(不同的)
例如

MariaDB [sandbox]> select status,username from users;
+--------+----------+
| status | username |
+--------+----------+
|     14 | John     |
|     13 | Jane     |
|     12 | Ali      |
|     11 | Bruce    |
|     10 | Martha   |
|      9 | Sidney   |
|      8 | charlie  |
|      7 | Elisa    |
|      6 | Samantha |
|      5 | Hannah   |
|      5 | Hannah   |
|      3 | Kevin    |
+--------+----------+
12 rows in set (0.00 sec)

MariaDB [sandbox]> select status,count(*), count(distinct username) from users group by status;
+--------+----------+--------------------------+
| status | count(*) | count(distinct username) |
+--------+----------+--------------------------+
|      3 |        1 |                        1 |
|      5 |        2 |                        1 |
|      6 |        1 |                        1 |
|      7 |        1 |                        1 |
|      8 |        1 |                        1 |
|      9 |        1 |                        1 |
|     10 |        1 |                        1 |
|     11 |        1 |                        1 |
|     12 |        1 |                        1 |
|     13 |        1 |                        1 |
|     14 |        1 |                        1 |
+--------+----------+--------------------------+
11 rows in set (0.00 sec)

注意状态5。

相关问题