Jump to content

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

Go to solution Solved by Barand,

Recommended Posts

I think the addition of the last line will do it

    , COUNT(*) as `Count`
    , GROUP_CONCAT(datarichiesta,' (',result,')' ORDER BY datarichiesta SEPARATOR ' , ') as Dates
    , @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

Top Posters In This Topic

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




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?


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.