lundi 12 octobre 2015

Sqlite select and insert last value from another table matched by id

I have asked question before, but I was not clear enough, I apologize.

I have following example tables: 
HistoricalValue
ID  SITEID  VAL DATE
1   1      100  9/1
2   1      120  10/1
3   2      300  10/3
4   2      350  10/10 

LOG
ID  SITEID  VAL   START_TIME    END_TIME    CALC
1     1     120      10:10      10:20       (END_TIME-START_TIME)*VAL

HistoricalValue table is where I enter data for each of the site, and the LOG table is where I would enter some of the parameters to calculate on.

What I want is to auto populate "VAL(ue)" column in LOG table with the last value (by id? or maybe by date) from HistoricalValue table based on the SiteID that is selected.

What is the proper way to achieve this?

Thank you in advance.

Aucun commentaire:

Enregistrer un commentaire