-2

My table name is 'bills' i want the sum of columns Electricity and gas and their sum should automatically stored in the column named as Total.Which trigger can do this work please tell me its correct code.I have searched a lot but didn't got my answer.

Electricity+Gas=Total
1            2   3
Sid M
  • 4,354
  • 4
  • 30
  • 50
evo
  • 1
  • 2
    I doubt, that you searched a lot. Do you even know the slightest about MySQL? Is this for a homework? We don't do homework around here. – yunzen Jun 27 '14 at 10:31
  • http://stackoverflow.com/questions/5223732/mysql-table-creation-with-default-valueexpression-to-a-column – R D Jun 27 '14 at 10:52

1 Answers1

0

Sorry, if HerrSekurr is correct and this is homework, it's a trick question.

Tell your teacher: "Teacher, one should never store a derived result back into a table. The beauty and power in SQL is the ability to generate the desired query with the CURRENT data."

To do so: "select electricity, gas, sum(electricity + gas) from your_table"

Now, if you want an index (maybe that's the database term you really meant), accept my answer, then ask a new question...

user3741598
  • 297
  • 1
  • 12