我有表等SQL计数平均
id userid semid courseid coursename total
1 36 17 13 CA 23
2 36 17 5 CB 46
3 36 17 8 CC 20
4 36 19 16 CD 34
5 36 19 13 CA 31
6 36 19 3 CA# 29
7 36 19 7 CE 60
8 36 10 9 CK 32
9 36 10 15 CH 56
我需要semid的平均输入用户名字,即,SUM(courseid)/数(的moduleId),它被示出9作为模块计数,但我只有3模块。 这是我的查询
SELECT userid, SUM(total)/count(semid) FROM custom WHERE userid=36
9从'count'返回行数,并且不计算该列的唯一值的数量(假设您正在对特定示例运行查询...否则我不确定在哪里9将来自 – MxyL 2012-08-08 08:03:38
count(semid)给你9,因为有9行为36,如果你需要不同的semid,使用关键字“distinct” – Kamal 2012-08-08 08:05:51