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:…
Tag: sql
Oracle SQL Inserting multiple rows into a table while referencing 2 FK
I’m trying to insert values id_team_FK and id_location_FK which both come from the same table. For example id_team_FK = 4 and id_location_FK = 150. The problem is, id_team_FK must be a randomly chosen …
SQL result from table a but name from table b
My request is quiet simple however I can’t find it (maybe I can’t goolge correctly). I have Table A and Table B Table A: ID length 1 50 2 45 2 20 and Table B ID name 1 apple 2 orange I want …
Why are postgresql tables empty although filled when starting Testcontainer?
I am using Testcontainers 1.15.2 (using postgres image 13.2-alpine) with Spring Boot 2.4.3. The Testcontainer is started using an init script which starts with a type definition, a table creation and …
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 ‘…
Laravel (8.x) Is there a better Eloquent query for this many-to-many filtering problem?
What I have movies many-to-many stars movies many-to-many tags studio one-to-many movies I pass studio name, star name and/or tag name as optional query strings What I need Select all movies with tag and star and studio if all 3 are passed as params Select all movies with tag and star if those 2 are passed as…
Do I need to perform a Join in order to merge multiple columns with 0 in them
I may have asked this question incorrectly but I have the following query where I’m trying to pull 3 different metrics for a given store. When I pull them though it comes out as below: Is there a way …
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) …
How to do a join to get previous days values?
I want to join tables as follow: Report_Period Entity Tag Users Count Report_Period_M-1 Report_Period_D-1 … 2021-03-31 entity 1 X 471 2017-05-31 2021-03-18 … 2020-12-31 entity 2 A 135 2020-11-30 2021-03-18 … 2020-11-30 entity 3 X 402 2020-10-31 2021-03-18 … With a view containing Day &…