0
 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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Ruckser
  • 47
  • 1
  • 9
  • 1
    Why are these three tables to begin with? They are all identical in structure (at least based on what you have shown us), so that should rather be one single table. – CBroe Jul 06 '17 at 13:10
  • You should really use joins with those IDs instead of in the WHERE clause – Cup of Java Jul 06 '17 at 13:14
  • This is just a sample, if i put the really work it will confuse you that is why i decided to use simple data @CBroe – Ruckser Jul 06 '17 at 13:30
  • Can you give me an example if you don't care @CupofJava – Ruckser Jul 06 '17 at 13:31
  • @Ruckser here is a good post explaining it and why https://stackoverflow.com/questions/2241991/in-mysql-queries-why-use-join-instead-of-where – Cup of Java Jul 06 '17 at 13:34
  • See: [Why should I provide an MCVE for what seems to me to be a very simple SQL query?](https://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a-very-simple-sql-query) – Strawberry Jul 06 '17 at 13:34
  • Let me go through it @CupofJava – Ruckser Jul 06 '17 at 13:51
  • Thanks let me go through it too @Strawberry – Ruckser Jul 06 '17 at 13:51

0 Answers0