0

I'm wondering how to add several values together. For example, I have a table1:

#|a1|a2|a3
-|--|--|--
1|##|##|##
2|##|##|##
3|##|##|##

and a table2:

#|b1|b2|b3
-|--|--|--
1|##|##|##
2|##|##|##
3|##|##|##

I want to get:

y = sum(a1) + b1(3)  -- Sum of a1 and the third element of b1.

Also, How can I do more complex functions like:

y = (a1(2) * 3 + b2(2) * a3(2)) / avg(b1)
Insane Skull
  • 9,220
  • 9
  • 44
  • 63
Bing Gan
  • 415
  • 3
  • 6
  • 12

1 Answers1

0

You can use Group by to get sum(a1) of table1.

Then you will need to join table2 on some condition.

Also, you need to specify the ordering condition for b1(3).

Look at: MySQL row order for “SELECT * FROM table_name

insertion time ordering is not guaranteed in mysql. Once you specified the ordering, you can use top 3 row by 'Limit' keyword. Ref: How do you select every n-th row from mysql

Community
  • 1
  • 1
LKW
  • 180
  • 1
  • 3
  • 13