Skip to content

Tag: sql

Calculate percentage of students SQL

How to calculate percentage of students with higher mark than average for each course? Assume I have a table (avg_marks) with average marks for each course and number of students in the course: I also have a table (enrolments) with all courses, students enrolled in those courses and their mark for the course:…

Creating a row number column based on another columns value

I have the following data: it’s a calendar that has date and year/week number there week is our internal calendar. what i want to do is sort by the most recent week number and have that be rel_week_index=1, and then the previous week be rel_week_index=2, etc. I got this to work by doing ROW_NUMBER() OVE…

MySQL Java prepared statement Syntax error

I need to select rows from mysql table based on various criteria, for example Colour= Black, or size= L. The code works without the preparedstatement and the question marks, but whenever I attempt to use the question marks the code does not run. I have read something about typing the question mark like &#8216…

SQL – % Breakout by Hour

I’m trying to write a query that will break out what percentage of time is utilized within a hour given a time range. Sample data: declare @date table(id int, Start_time time, End_time time) …