我在 SQL Server 2012 中有查询以查看我公司的用户部门。
SELECT mdl_user_info_data.data
FROM
dbo.mdl_user,
dbo.mdl_course,
dbo.mdl_user_enrolments,
dbo.mdl_enrol,
dbo.mdl_course_categories,
dbo.mdl_user_info_data
WHERE
mdl_course.id = mdl_enrol.courseid AND
mdl_enrol.id = mdl_user_enrolments.enrolid AND
mdl_user_enrolments.userid = mdl_user.id AND
mdl_course.category = mdl_course_categories.id AND
mdl_course.id = 3 and
mdl_user_info_data.fieldid = 3 and
mdl_user.id = mdl_user_info_data.userid
我的查询结果是:
|data|
|CIS|
|CIS|
|TOP|
但我想要的是这样的:
|DATA| TOTAL |
|CIS | 2 |
|TOP | 1 |
有人可以帮助我吗?总之感谢。
我的 mdl_user_info_data 属性:
[id] [bigint] IDENTITY(1,1) NOT NULL,
[userid] [bigint] NOT NULL,
[fieldid] [bigint] NOT NULL,
[data] [ntext] NOT NULL,
[dataformat] [smallint] NOT NULL,
mdl_user_info_data 中的某些行:
id userid fieldid data dataformat
3 3 3 CIS 0