嗨 StackOverFlow 成员
报告 = 表名。
数据库
CREATE TABLE `reports` (
`id` int(11) NOT NULL auto_increment,
`report_day_name` varchar(20) NOT NULL,
`report_day` varchar(20) NOT NULL,
`report_month` varchar(20) NOT NULL,
`report_year` varchar(20) NOT NULL,
`report_result_number` varchar(20) NOT NULL,
`report_result_text` varchar(20) NOT NULL,
`report_since` varchar(20) NOT NULL,
`report_date` varchar(20) NOT NULL,
`catid` int(11) NOT NULL,
`subjectid` int(11) NOT NULL,
`userid` int(11) NOT NULL,
`groupid` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=78 ;
INSERT INTO `reports` VALUES (73, 'day', '14', '1', '1434 h', '5', 'rate', '1234567890', '1434-1-14', 1, 132, 33, 35);
INSERT INTO `reports` VALUES (74, 'day', '12', '2', '1435 h', '4', 'rate', '1234567890', '1434-2-12', 2, 136, 36, 35);
INSERT INTO `reports` VALUES (75, 'day', '14', '1', '1434 h', '2', 'rate', '1354488730', '1434-1-14', 1, 132, 33, 35);
INSERT INTO `reports` VALUES (76, 'day', '12', '2', '1435 h', '4', 'rate', '1354488730', '1434-2-12', 2, 137, 36, 35);
INSERT INTO `reports` VALUES (77, 'day', '12', '2', '1435 h', '1', 'rate', '1354488730', '1434-2-12', 2, 134, 33, 35);
这是数据库表:
id report_result_number subjectid userid
73 5 132 33
74 4 136 36
75 2 132 33
76 4 137 36
77 1 134 33
我想要SUM(reports.report_result_number) where (reports.subjectid) is DISTINCT
当我运行这段代码时..
选择 users.user_id, users.user_name, users.user_country, SUM(reports.report_result_number) AS AllTotal, COUNT(DISTINCT reports.subjectid) AS TotalSubjects 从 用户 INNER JOIN 报告 users.user_id = reports.userid 通过...分组 users.user_id 订购方式 全部 DESC 限制 4
它返回 AllTotal
user_id user_name user_country AllTotal TotalSubjects
36 name country 8 (correct) 2
33 name country 8 (not correct) 2