List:General Discussion« Previous MessageNext Message »
From:Roy Walker Date:July 11 2003 5:19am
Subject:Complex select statement
View as plain text  
If anyone could tell me what I am doing wrong here, I would greatly appreaciate it.
 
Have the following tables:
 
table1: id, count
table2: id, count, period_count, date, timestamp
 
Trying to do the following; get all rows from table 1 and insert them into table2 while setting period_count to count.table1 minus the most recent entry for that id in count.table2, then set the date field to the previous day.
 
Here goes:
 
INSERT INTO table1 (id,count,period_count,date) SELECT id,count FROM table1, (count.table1 - (SELECT count FROM table2 WHERE MAX(timestamp) AND id.table2=id)) AS period_count, date='TO_DAYS(NOW() -1)';

Sorry if this is easy, but I could not find an example of any mathematic functions while doing an INSERT ... SELECT.
 
Thanx,
Roy
Thread
Complex select statementRoy Walker11 Jul
RE: Complex select statementRoy Walker11 Jul
  • Re: Complex select statementEgor Egorov11 Jul
  • Re: Complex select statementNils Valentin12 Jul
RE: Complex select statementRoy Walker11 Jul
RE: Complex select statementRudy Metzger14 Jul
RE: Complex select statementRoy Walker15 Jul
  • Re: Complex select statementMichael Iatauro15 Jul
RE: Complex select statementRoy Walker16 Jul
RE: Complex select statementRudy Metzger16 Jul