Barand Posted May 13, 2015 Share Posted May 13, 2015 I think the addition of the last line will do it SELECT User , COUNT(*) as `Count` , GROUP_CONCAT(datarichiesta,' (',result,')' ORDER BY datarichiesta SEPARATOR ' , ') as Dates FROM ( SELECT datarichiesta , @N := IF((codicepz<>@prevuser) OR (@prevres < 10) OR (risultato < 10) OR (datarichiesta > @startdate + INTERVAL 6 MONTH) , @N+1, @N) as groupno , @startdate := IF((codicepz<>@prevuser) OR (@prevres < 10) OR (risultato < 10) OR (datarichiesta > @startdate + INTERVAL 6 MONTH) , datarichiesta, @startdate) as startdate , @prevres:=risultato as result , @prevuser:=codicepz as user FROM mastertot JOIN ( SELECT @N:=0, @prevres:=NULL, @prevuser:=NULL ) as init WHERE descrprestaz = 'a1' ORDER BY codicepz, datarichiesta ) as detail GROUP BY user,groupno HAVING `Count` >= 5 AND MIN(datarichiesta) + INTERVAL 1 MONTH < MAX(datarichiesta); Link to comment https://forums.phpfreaks.com/topic/296198-copy-all-records-with-2-equals-data-from-table1-to-one-record-in-table2-second-part/page/3/#findComment-1511803 Share on other sites More sharing options...
paolo123 Posted May 14, 2015 Author Share Posted May 14, 2015 Yes! Thanks!! i did not think about inserting this dates restriction on groups at end, when all groups are already populated! It is not so immediate enter in the SQL logic. Could you suggest me a good tutorial or book about SQL ? Link to comment https://forums.phpfreaks.com/topic/296198-copy-all-records-with-2-equals-data-from-table1-to-one-record-in-table2-second-part/page/3/#findComment-1511834 Share on other sites More sharing options...
Barand Posted May 14, 2015 Share Posted May 14, 2015 Alas, I can't. I have never read one, except manuals. There is good video tutorial on data normalization http://forums.phpfreaks.com/topic/273634-best-way-to-set-up-tables-when-multiple-values/?do=findComment&comment=1408360 If you get the data right it can make life easier, at least where SQL is concerned. Link to comment https://forums.phpfreaks.com/topic/296198-copy-all-records-with-2-equals-data-from-table1-to-one-record-in-table2-second-part/page/3/#findComment-1511836 Share on other sites More sharing options...
paolo123 Posted May 14, 2015 Author Share Posted May 14, 2015 i was also thinking about coping data in php vectors in order to search for more complex time analysis profile. Do you think it is a good idea? There are particular dimension limit for vectors in php or other type of negative aspects like long elaboration time? Thanks Link to comment https://forums.phpfreaks.com/topic/296198-copy-all-records-with-2-equals-data-from-table1-to-one-record-in-table2-second-part/page/3/#findComment-1511838 Share on other sites More sharing options...
Barand Posted May 14, 2015 Share Posted May 14, 2015 You would be limited by available memory echo ini_get('memory_limit'); If you want to monitor usage memory_get_usage, memory_get_peak_usage Link to comment https://forums.phpfreaks.com/topic/296198-copy-all-records-with-2-equals-data-from-table1-to-one-record-in-table2-second-part/page/3/#findComment-1511843 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.