Jump to content

Copy all records with 2 equals data from table1 to one record in table2 (second part)


paolo123

Recommended Posts

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
Share on other sites

  • Replies 54
  • Created
  • Last Reply

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
Share on other sites

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
Share on other sites

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
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.