|student_id |subject |marks|
|
|1001 english 75|
|1001 maths 80|
|1001 science 70|
|1001 english 90|
|1001 maths 95|
|1001 science 85|
required output:
student_id English Maths Science
1001 75 80 70
1002 90 95 85
so how to get the result as expected am new to sql. Thanks in advance and note that the records are having 1001 as ids intentionally
Related
table_1
ST_ID NAME MATHS GEOGRAPHY ENGLISH
1001 Alan Wegman 80 85 70
1002 Robert Franko 79 65 60
1003 Francis John 90 75 67
1004 Finn Harry 88 87 93
table_2
ST_ID NAME MATHS GEOGRAPHY ENGLISH
2001 Alan Wegman 69 75 80
2002 Robert Franko 99 85 70
2003 Francis John 80 65 77
2004 Finn Harry 78 97 83
table_3
ST_ID NAME MATHS GEOGRAPHY ENGLISH
3001 Alan Wegman 90 81 72
3002 Robert Franko 97 65 61
3003 Francis John 74 75 67
3004 Finn Harry 77 88 73
From above three tables, i want to to the following, i want to take value of MATHS of student Alan Wegman which is 80 divide by 100 from TABLE 1 then take value of GEOGRAPHY of the same student Alan Wegman which is 85 divide by 100 from TABLE 3 then from last table take value of ENGLISH of same student Alan Wegman which is 70 divide by 100 then they should be added to get one value like this example (80/100+85/100+70/100) and output should be displaying NAME and total value after addition example below
Alan Wegman 2.27
Robert Franko 2.11
Finn Harry 3.29
Is this really possible? i want this to be performed by a single query for all records or if there is an alternative way of doing this please share with me, the query i am trying to achieve this result is this one below but it does not return any thing i don't know where am wrong.
select
table_1.NAME MATHS/100+table_2.NAME GEOGRAPHY/100+table_3.NAME ENGLISH/100
WHERE table_1.NAME = table_2.NAME = table_3.NAME
I am not competent with mysql need help here guys.
I am using this SQL:
TRANSFORM Max(table1.[quiz]) AS MaxOfquiz
SELECT table1.[quizdate], table1.[studentname], Max(table1.[quiz]) AS [Total Of
quizscores]
FROM table1
GROUP BY table1.[quizdate], table1.[studentname]
PIVOT table1.[coursename];
To try and pivot a combobox table:
Table1
ID quizdate coursename studentname quiz
1 02-Jan-21 math john 100
2 03-Feb-21 science joe 99
3 04-Mar-21 physics monica 97
4 05-Apr-20 language mike 88
Where coursename is a dropdown (math, science, physics, language) into
Table 2
studentname math science physics language
john 100
joe 99
monica 97
mike 88
I got these results:
quizdate studentname Total Of quizscores 1 2 3 4
4/4/2016 moe 88 88
1/1/2017 john 100 100
2/2/2017 joe 99 99
3/3/2017 monica 97 97
It seems that combox box coursename can't be pivoted as column name, but the
numbers instead. Can anyone explain how I can generate the correct results?
You answer it yourself:
Where coursename is a dropdown (math, science, physics, language)
So, in the query, the value from the field will be the ID of these "dropdowns".
To obtain coursenames, move these to a separate table and join this with Table1 in your query.
I have this table that has the name of the employee and their phone time duration in mysql. The table looks like this:
Caller Emplid Calldate Call_Duration
Jack 333 1/1/2016 43
Jack 333 1/2/2016 45
Jack 333 1/3/2016 87
Jack 333 2/4/2016 44
Jack 333 2/5/2016 234
jack 333 2/6/2016 431
Jeff 111 1/1/2016 23
Jeff 111 1/2/2016 54
Jeff 111 1/3/2016 67 48
I am trying to calculate the running Daily average of each employee total_Duration by day each month. Suppose I have daily running average for the month of April, then the running average for the May should start from 1st of may and end on 31st of that month. I have tried doing many ways and mysql does not have pivot and partition function like sql server. The total employee who made the call changes daily, I need something that dynamically takes care of no of employees that makes call.
The output should look like this:
Caller Emplid Calldate Call_Duration Running_avg
Jack 333 1/1/2016 43 43
Jack 333 1/2/2016 45 44
Jack 333 1/3/2016 87 58.33333333
Jack 333 2/4/2016 44 44
Jack 333 2/5/2016 234 139
Jack 333 2/6/2016 431 236.3333333
Jeff 111 1/1/2016 23 23
Jeff 111 1/2/2016 54 38.5
Jeff 111 1/3/2016 67 48
This is the query that I started below:
SELECT row_number,Month_Year,Callername,Calldate,Caller_Emplid,`Sum of Call`,`Sum of Call`/row_number as AvgCall,
#`sum of call`:=#`sum of call`+ `sum of call` overallCall,
#row_number:=row_number overallrow_number,
#RunningTotal:=#`sum of call`/#row_number runningTotal
FROM
(SELECT
#row_number:=
CASE WHEN #CallerName=CallerName and date_format(calldate,'%d') = date_format(calldate,'%d') and
date_format(calldate,'%m') = date_format(calldate,'%m')
THEN #row_number+1
ELSE 1 END AS row_number,#CallerName:=CallerName AS Callername,Calldate,Caller_Emplid,Month_Year,`Sum of Call`
FROM transform_data_2, (SELECT #row_number:=0,#CallerName:='') AS t
ORDER BY callername) a
JOIN (SELECT #`Sum of call`:= 0) t
A list showing each product requested on each client stock request. Show client name, product number and quantity requested. Sorted by client name and then product number.
I tried this:
SELECT STOCK_REQUEST.requestNum, STOCK_REQUEST.clientNum, CLIENT.clientName, REQUEST_LIST.productNum, REQUEST_LIST.qtyRequested
FROM STOCK_REQUEST, CLIENT, REQUEST_LIST
WHERE CLIENT.clientNum = STOCK_REQUEST.clientNum
AND REQUEST_LIST.requestNum = STOCK_REQUEST.requestNum
ORDER BY CLIENT.clientName AND REQUEST_LIST.productNum
I get sth like this:
requestNum clientNum clientName productNum qtyRequested
2 2 [->] David Liu 4 674
3 2 [->] David Liu 5 66
1 1 [->] Ian Peng 2 45
5 4 [->] James Cameron 3 809
4 3 [->] Mark Moris 1 164
But the requirement says we have to use sub-query, so I try to change it to:
SELECT CLIENT.clientName, REQUEST_LIST.productNum, REQUEST_LIST.qtyRequested
FROM CLIENT, REQUEST_LIST
WHERE CLIENT.clientNum IN (
SELECT clientNum
FROM STOCK_REQUEST)
AND REQUEST_LIST.requestNum IN (
SELECT requestNum
FROM STOCK_REQUEST)
ORDER BY CLIENT.clientName AND REQUEST_LIST.productNum
But the result is not what I expect:
clientName productNum qtyRequested
David Liu 4 674
James Cameron 3 809
Mark Moris 5 66
David Liu 2 45
James Cameron 1 164
Mark Moris 4 674
James Cameron 5 66
Mark Moris 2 45
Ian Peng 3 809
James Cameron 4 674
Ian Peng 1 164
James Cameron 2 45
David Liu 3 809
Ian Peng 5 66
David Liu 1 164
Ian Peng 4 674
Mark Moris 3 809
David Liu 5 66
Ian Peng 2 45
Mark Moris 1 164
Can someone show me the easiest way to normalize this table? I'm having trouble figuring out how to group relationships.
Film# Title Dir# DirectorName Actor# ActorName Role Timeon
F1100 Happy Day D101 Jim Alan A1000 Judy Foster Amy Jones 50
A1001 Robert Dinero Harry 30
A1004 Harrison Ford Jack Actress 55
A1009 Eddy Murphy Excel Fuse 65
A1000 Judy Foster Amy Jones 15
F1101 AirForceOne D105 Woody Ellen A1000 Judy Foster Amy Jones 50
A1004 Harrison Ford Bill Ford 55
A1009 Eddy Murphy Police one 35
A1002 Mary Jackson Police two 45
F1102 RunAwayBride D101 Jim Alan A1003 Julia Roberts Amy Jones 50
A1007 David Lynch Sam Strickland 45
A1004 Harrison Ford Robber 35
A1005 John Wayne Cab Driver 25
A1000 Judy Foster News Reporter 65
You need two data tables, Film and Person, and two intersection tables, FilmDirector and FilmRole. An abbreviated example:
Film
filmID title
1100 Happy Day
1101 Airforce One
1102 Runaway Bride
Person
personID name
101 Jim Alan
105 Woody Ellen
1000 Judy Foster
1001 Robert Dinero
1002 Mary Jackson
1003 Julia Roberts
1004 Harrison Ford
1005 John Wayne
1007 David Lynch
1009 Eddy Murphy
FilmDirector
filmDirectorID filmID personID
1 1100 101
2 1101 105
3 1102 101
FilmRole
filmRoleID FilmID personID role timeOn
1 1100 1000 Amy Jones 50
2 1100 1001 Harry 30
3 1100 1004 Jack Actress 55
6 1101 1000 Amy Jones 50
7 1101 1004 Bill Ford 55
...