-7

I have multiple tables in my project and I want to count out something from a table which is video table , first let me attach the table Images...

enter image description here

above is table_std

enter image description here

above is tablesubject

enter image description here

above is table_chapter

enter image description here

above is table video

now I want to fund total sum of videotime which is in the tbvid and want it against stdid like below enter image description here

so here first it all starts with standard table , next table subtable is dependent of std table then chap table is depends over sub table and vid table depends over chap table.

for me the sql query is going to be very difficult if anyone can help me with this , it will be so appreciated !

Nisarg Jani
  • 415
  • 2
  • 12
  • 5
    Do **not**, **never**, **never ever** post images of tables. Post the `CREATE` and `INSERT` statements as **text**. – sticky bit Nov 13 '21 at 14:20
  • You have a chronic abbreviation problem. "vidtime" instead of "video_time", "subdesc" insteand of "subject_description". I still cannot work out what "std" stands for. Is it "standard" or "student"? Who knows? You may think this kind of abbreviations make your code look cool, but in the end you just make it difficult to read. – KIKO Software Nov 13 '21 at 14:33
  • @KIKOSoftware this is just for an example , std stands for standard here ! – Nisarg Jani Nov 13 '21 at 15:00
  • @stickybit images helps to understand everything very fast and easily – Nisarg Jani Nov 13 '21 at 15:01
  • 2
    @NisargJani: Images aren't (easily) consumable and therefore make it needlessly hard for people to built up test environments to work on *your* problem. Make it as easy as possible for those people and use proper DDL and DML -- help those who help you -- don't use images! – sticky bit Nov 13 '21 at 15:09
  • 2
    Nisarg Jani as @sticky bit mentioned before posting images instead of text makes people wasting a lot of time doing examples and tests for your problem. In my opinion it is pointless answering a question that doesn't provide minimal effort to at least making the question easier to reproduce in a test environment. It will take maybe more than 20 minutes only creating the tables . Copy paste needs only some seconds.Help us to help you. – Ergest Basha Nov 13 '21 at 15:25
  • 1
    Examples also need to be comprehensible and usable. Also, "it's just an example", and "I'll do it correct later", are some of the most frequent excuses we hear here. Sorry to be so tough on you, we mean well, I hope you can understand that. My advice is: Delete this question, and start again, this time without the images, and with your own best attempt at solving your problem. – KIKO Software Nov 13 '21 at 15:33

1 Answers1

0

Refer from SUM(subquery) in MYSQL

SELECT `std`.*,
    (SELECT SUM(`video`.`vidtime`) FROM `video` WHERE `vidid` = `std`.`stdid`) AS `sum_vidtime`
FROM `table_std` AS `std` 

If you want to use only these columns: stdid, vidtime (sum_vidtime in my case) then it is no need to join multiple tables. Use sub query.

And as everyone said, please don't use image for an example.

vee
  • 4,506
  • 5
  • 44
  • 81
  • ok I tried but in my case there are 4 tables , each table depends on another for me it didn't work ! – Nisarg Jani Nov 13 '21 at 19:21
  • 1
    In that case do like every one said, post `CREATE` and `INSERT` for example code. Or delete this question and start again with **text** not **image** as @KIKO commented. – vee Nov 14 '21 at 09:59