wonder Posted February 14, 2013 Report Share Posted February 14, 2013 Haiz! Man pašlaik ir divas tabulas: Tabulā 1 atrodas šādi lauki: ID | DATE | COUNT | Tabulā 2 ir šādi lauki: PID | DATE | TITLE | 12 | 2013-02-14 | Title 1 | 39 | 2013-02-14 | Title 16 | Pagaidām Tabulā 1 lauki ir tukši, jo nespēju izdomāt kā viņus aizpildīt. Man ir nepieciešams no tabulas 2 saskaitīt viena konkrēta datuma ierakstus un pēctam tos ievietot tabulā 1. Beigās vajadzētu visam izskatīties šādi tabulā 1. ID | DATE | COUNT | 1 | 2013-02-14 | 2 | Tabulā 2 būs tikai pašreizējās dienas datums, jo dienas beigās ar cron dati tiks dzēsti, bet tas notiks pēctam, kad tie ir saskaitīti un ielikti tabulā 1. insert Into tabula1 (select DATE from tabula2) Ar šo vajadzētu strādāt ielikšana, bet kā lai saskaita un uzreiz ieliek tabulā 1? Quote Link to comment Share on other sites More sharing options...
Kavacky Posted February 14, 2013 Report Share Posted February 14, 2013 Kaut kā šitā: INSERT INTO `tabula` (`date`, `count`) VALUES ( DATE(DATE_SUB(NOW(), INTERVAL 1 DAY)), (SELECT COUNT(*) FROM `table2` WHERE `date`=DATE(DATE_SUB(NOW(), INTERVAL 1 DAY)) ) Quote Link to comment Share on other sites More sharing options...
draugz Posted February 14, 2013 Report Share Posted February 14, 2013 (edited) Ideja jau ir pareize :) Es uzlikti unikalo atslegu uz date un izpilditu sadu skriptu insert into tabula1 (date, count) (SELECT date, count(*) FROM tabula2 group by date ) on duplicate key update count=VALUES(count) Edited February 14, 2013 by draugz Quote Link to comment Share on other sites More sharing options...
renarti Posted February 14, 2013 Report Share Posted February 14, 2013 insert into table2 (date,count) select table1.date, count( table1.title) from table1 group by table1.date Quote Link to comment Share on other sites More sharing options...
draugz Posted February 14, 2013 Report Share Posted February 14, 2013 Ideja jau ir pareize :) Es uzlikti unikalo atslegu uz date un izpilditu sadu skriptu insert into tabula1 (date, count) (SELECT date, count(*) FROM tabula2 group by date ) on duplicate key update date=IF(VALUES(date) > date, VALUES(date), date) Quote Link to comment Share on other sites More sharing options...
wonder Posted February 14, 2013 Author Report Share Posted February 14, 2013 Paldies jums! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.