473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Count and group Marks by Student

2
Hi
I have a this Table;
Expand|Select|Wrap|Line Numbers
  1. +-----------+--------------+------+---------------------+---------+-------+----------+-------+
  2. | StudentID | AcademicYear | Term |     StudentName     |  Class  | Marks | Position | Count |
  3. +-----------+--------------+------+---------------------+---------+-------+----------+-------+
  4. |     12013 |         2015 | One  | Adamu A. Msangi     | Form IV |    80 |        1 |     5 |
  5. |     52013 |         2015 | One  | Angela M. Lucas     | Form IV |    67 |        2 |     5 |
  6. |     22014 |         2014 | Two  | Agness Daudi Martin | Form II |    60 |        3 |     5 |
  7. |     32014 |         2014 | Two  | Agness John Missana | Form II |    51 |        4 |     5 |
  8. |     42013 |         2015 | One  | Andrea F. Agustino  | Form IV |    50 |        5 |     5 |
  9. +-----------+--------------+------+---------------------+---------+-------+----------+-------+
  10.  
Which i have got by running the Sql Script below:

Expand|Select|Wrap|Line Numbers
  1.  SELECT * ,
  2. ROW_NUMBER() OVER (ORDER BY Marks DESC) AS Position,  count(StudentID) OVER() AS 'Count'FROM Student
The output I'm looking for should show the student Position and Total number of Students. For example if I Query Student with ID No; 42013 and Term='One' and AcademicYear=2015 and Class='Form IV', I should get results similar with the following table:

Expand|Select|Wrap|Line Numbers
  1. +-----------+--------------+------+--------------------+---------+-------+----------+-------+
  2. | StudentID | AcademicYear | Term |    StudentName     |  Class  | Marks | Position | Count |
  3. +-----------+--------------+------+--------------------+---------+-------+----------+-------+
  4.  
  5. |     42013 |         2015 | One  | Andrea F. Agustino | Form IV |    50 |        5 |     3 |
  6.  
Thanks
Feb 14 '17 #1
1 1605
Sandet
2
Thanks I have solved it using this code
Expand|Select|Wrap|Line Numbers
  1. select *
  2. from (
  3.     select t.*, ROW_NUMBER() over (
  4.             order by sum(Marks) desc
  5.             ) as Position, count(StudentID) over (PARTITION BY term, class, academicyear) as Student_count
  6.     from Student t    Group by StudentID, AcademicYear, Term, Class, StudentName, Marks
  7.     ) t
  8.  
  9. where StudentID=42013
  10.  
Feb 15 '17 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Joseph Santaniello | last post by:
Hello all, I have a table with among other things a timestamp field. To get the count of records per hour I do: select count(*) as c, date_trunc('hour', timestmp) as h from mytable
2
by: Chris | last post by:
Hello all, I'm having some trouble setting up a query. Background: The table TBLSCREEN stores data about screenings of patients/subjects for eligibility to participate in a health study. A...
1
by: mjobrien | last post by:
Thanks for the hint Allen (see below). But I am already doing that count as total records read (5)in the report footer. That count is unduplicated for the record not for the field - student ID as...
8
by: Thomas | last post by:
Hi! I´m a newbie with this and I´m trying to build a forum of my own but have stumbled on my first problem as early as the opening page. To the problem: I want to show a simple forum layout...
4
by: Igor | last post by:
I have one SELECT statement that needs to return one ntext field from one table and count something from other table, problem is that all fileds that are not in count have to be in group by and...
1
by: zafm86 | last post by:
Hi everyone! I'm sure my problem is pretty easy to solve but I've been working on it for a long and my my brain is not working correctly anymore. I'm working with an AS400 and I mhave to do an...
4
by: wadecarlson | last post by:
hey guys i have a problem with dups in my statement. ive tried using multiple select statements but i just cant get it. any help would be greatly appreciated. here is the sql: SqlJunk = "...
2
by: arial | last post by:
I need to write a query which would give me result like this: name Code1 code2 code3 ect J Doe 10 2 3 J Smith 8 ...
2
by: ArcticCircuits | last post by:
Greetings, As part of my Highschool project I had to come up with a themed database with a bunch of tables to query from, so I came up with a 'police' database. I am trying to get a count of all...
2
by: achikeziey | last post by:
select mobile ,count(id) from (select mobile ,id from phone_1204 where astatus='newsub' and left(service,4)='euro' union all select mobile,id from phone_1205 where astatus='newsub' and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.