1

enter image description hereI have a query which i am not able to figure out since i am new with sql and i have a project due tomorow to submit

any help will be appreciated

i have a registration table which has the following structure

Student_ID int,
Course varchar(15),
Score int,
Semester varchar(15),
Discipline varchar(10),
Campus varchar(15),
Degree varchar(10),
Year int

the Registration table has no Primary key it is basically for developing a date warehouse

so no primary key, and the data in this table is from 4 different campuses of the same university so Student_id is repeated a number of times

The Query is that i need to find average number of students in every batch(YEAR) of each campus

kindly help me if any one can

4

3 回答 3

0
DECLARE @Num_Discipline AS INT

SELECT DISTINCT @Num_Discipline = Count(Discipline)
FROM registration

SELECT Count(student_id) AS nStudents, Count(student_id)/@Num_Discipline AS Avg_Students
FROM registration
GROUP BY Campus, Year

Avg_Students这是特定年份每个校区的平均学生人数,假设校区有相同数量的学科。

于 2012-12-26T11:20:38.303 回答
0

我希望这是你所需要的::

给了我一些数据快照以便更好地理解。

select count(1),count(distinct student_id),year,count(distinct student_id)/count(1)   from   registration 
group by year;
于 2012-12-26T11:04:56.853 回答
0
select year, campus, count(distinct student_id)  from registration
       group by year, campus
于 2012-12-26T11:10:14.977 回答