merging two querys

Hi all,

I have two query that I I would like to be one, but I can't figure out
how to do it. (mysql 3.23)

$sql = sprintf ("SELECT task,SUM(hours),login FROM activities WHERE
login='%s' group by login",$usuario);

$sql2 = sprintf ("SELECT SUM(hours) FROM activities WHERE login='%s'
AND month='%s' group by login",$usuario,$getdate);

Thank you for any help.

Stefano
stefano.troiani [ Di, 24 Oktober 2006 09:09 ] [ ID #1511517 ]

Re: merging two querys

stefano.troiani [at] gmail.com wrote:
> Hi all,
>
> I have two query that I I would like to be one, but I can't figure out
> how to do it. (mysql 3.23)
>
> $sql = sprintf ("SELECT task,SUM(hours),login FROM activities WHERE
> login='%s' group by login",$usuario);
>
> $sql2 = sprintf ("SELECT SUM(hours) FROM activities WHERE login='%s'
> AND month='%s' group by login",$usuario,$getdate);
>
> Thank you for any help.
>
> Stefano

So which date are you expecting to see in your results?
zac.carey [ Di, 24 Oktober 2006 15:12 ] [ ID #1511518 ]

Re: merging two querys

stefano.troiani [at] gmail.com wrote:
> Hi all,
>
> I have two query that I I would like to be one, but I can't figure out
> how to do it. (mysql 3.23)
>
> $sql = sprintf ("SELECT task,SUM(hours),login FROM activities WHERE
> login='%s' group by login",$usuario);
>
> $sql2 = sprintf ("SELECT SUM(hours) FROM activities WHERE login='%s'
> AND month='%s' group by login",$usuario,$getdate);
>
> Thank you for any help.
>
> Stefano

Sorry, scrub my last post.

This should give you a clue:

SELECT login, SUM( hours ) AS time, GROUP_CONCAT( task
ORDER BY task
SEPARATOR ', ' ) AS tasks
FROM activities
WHERE login = '%s'
AND date = '%s'
GROUP BY login
LIMIT 0 , 30
zac.carey [ Di, 24 Oktober 2006 15:55 ] [ ID #1511519 ]

Re: merging two querys

strawberry wrote:
> stefano.troiani [at] gmail.com wrote:
> > Hi all,
> >
> > I have two query that I I would like to be one, but I can't figure out
> > how to do it. (mysql 3.23)
> >
> > $sql = sprintf ("SELECT task,SUM(hours),login FROM activities WHERE
> > login='%s' group by login",$usuario);
> >
> > $sql2 = sprintf ("SELECT SUM(hours) FROM activities WHERE login='%s'
> > AND month='%s' group by login",$usuario,$getdate);
> >
> > Thank you for any help.
> >
> > Stefano
>
> Sorry, scrub my last post.
>
> This should give you a clue:
>
> SELECT login, SUM( hours ) AS time, GROUP_CONCAT( task
> ORDER BY task
> SEPARATOR ', ' ) AS tasks
> FROM activities
> WHERE login = '%s'
> AND date = '%s'
> GROUP BY login
> LIMIT 0 , 30


thanks for your help, but I have 3.23 version of mysql and it does not
support GROUP_CONCAT.

Cheers,

stefano
stefano.troiani [ Mi, 25 Oktober 2006 09:45 ] [ ID #1512904 ]

Re: merging two querys

stefano.troiani [at] gmail.com wrote:
> strawberry wrote:
> > stefano.troiani [at] gmail.com wrote:
> > > Hi all,
> > >
> > > I have two query that I I would like to be one, but I can't figure out
> > > how to do it. (mysql 3.23)
> > >
> > > $sql = sprintf ("SELECT task,SUM(hours),login FROM activities WHERE
> > > login='%s' group by login",$usuario);
> > >
> > > $sql2 = sprintf ("SELECT SUM(hours) FROM activities WHERE login='%s'
> > > AND month='%s' group by login",$usuario,$getdate);
> > >
> > > Thank you for any help.
> > >
> > > Stefano
> >
> > Sorry, scrub my last post.
> >
> > This should give you a clue:
> >
> > SELECT login, SUM( hours ) AS time, GROUP_CONCAT( task
> > ORDER BY task
> > SEPARATOR ', ' ) AS tasks
> > FROM activities
> > WHERE login = '%s'
> > AND date = '%s'
> > GROUP BY login
> > LIMIT 0 , 30
>
>
> thanks for your help, but I have 3.23 version of mysql and it does not
> support GROUP_CONCAT.
>
> Cheers,
>
> stefano
3.23 !?!?!?!?!
UPGRADE!

Or, failing that:

SELECT [at] prev_login := NULL ;

SELECT login, SUM( hours ) AS time, MAX( [at] task :=
IF (
[at] prev_login = login, CONCAT_WS( ',', [at] task , task ) , task )
) AS task
FROM activities
WHERE login = '%s'
AND date = '%s'
GROUP BY login
LIMIT 0 , 30
zac.carey [ Mi, 25 Oktober 2006 15:46 ] [ ID #1512905 ]

Re: merging two querys

strawberry wrote:
> stefano.troiani [at] gmail.com wrote:
> > strawberry wrote:
> > > stefano.troiani [at] gmail.com wrote:
> > > > Hi all,
> > > >
> > > > I have two query that I I would like to be one, but I can't figure out
> > > > how to do it. (mysql 3.23)
> > > >
> > > > $sql = sprintf ("SELECT task,SUM(hours),login FROM activities WHERE
> > > > login='%s' group by login",$usuario);
> > > >
> > > > $sql2 = sprintf ("SELECT SUM(hours) FROM activities WHERE login='%s'
> > > > AND month='%s' group by login",$usuario,$getdate);
> > > >
> > > > Thank you for any help.
> > > >
> > > > Stefano
> > >
> > > Sorry, scrub my last post.
> > >
> > > This should give you a clue:
> > >
> > > SELECT login, SUM( hours ) AS time, GROUP_CONCAT( task
> > > ORDER BY task
> > > SEPARATOR ', ' ) AS tasks
> > > FROM activities
> > > WHERE login = '%s'
> > > AND date = '%s'
> > > GROUP BY login
> > > LIMIT 0 , 30
> >
> >
> > thanks for your help, but I have 3.23 version of mysql and it does not
> > support GROUP_CONCAT.
> >
> > Cheers,
> >
> > stefano
> 3.23 !?!?!?!?!
> UPGRADE!
>
> Or, failing that:
>
> SELECT [at] prev_login := NULL ;
>
> SELECT login, SUM( hours ) AS time, MAX( [at] task :=
> IF (
> [at] prev_login = login, CONCAT_WS( ',', [at] task , task ) , task )
> ) AS task
> FROM activities
> WHERE login = '%s'
> AND date = '%s'
> GROUP BY login
> LIMIT 0 , 30


Thanks, I will try this query, if you have a spare time, can you
explain me this query?
There are things that i don't understand like the first line and the
use of ':=' and ' [at] '


stefano
stefano.troiani [ Do, 26 Oktober 2006 10:15 ] [ ID #1514330 ]

Re: merging two querys

stefano.troiani [at] gmail.com wrote:
> strawberry wrote:
> > stefano.troiani [at] gmail.com wrote:
> > > strawberry wrote:
> > > > stefano.troiani [at] gmail.com wrote:
> > > > > Hi all,
> > > > >
> > > > > I have two query that I I would like to be one, but I can't figure out
> > > > > how to do it. (mysql 3.23)
> > > > >
> > > > > $sql = sprintf ("SELECT task,SUM(hours),login FROM activities WHERE
> > > > > login='%s' group by login",$usuario);
> > > > >
> > > > > $sql2 = sprintf ("SELECT SUM(hours) FROM activities WHERE login='%s'
> > > > > AND month='%s' group by login",$usuario,$getdate);
> > > > >
> > > > > Thank you for any help.
> > > > >
> > > > > Stefano
> > > >
> > > > Sorry, scrub my last post.
> > > >
> > > > This should give you a clue:
> > > >
> > > > SELECT login, SUM( hours ) AS time, GROUP_CONCAT( task
> > > > ORDER BY task
> > > > SEPARATOR ', ' ) AS tasks
> > > > FROM activities
> > > > WHERE login = '%s'
> > > > AND date = '%s'
> > > > GROUP BY login
> > > > LIMIT 0 , 30
> > >
> > >
> > > thanks for your help, but I have 3.23 version of mysql and it does not
> > > support GROUP_CONCAT.
> > >
> > > Cheers,
> > >
> > > stefano
> > 3.23 !?!?!?!?!
> > UPGRADE!
> >
> > Or, failing that:
> >
> > SELECT [at] prev_login := NULL ;
> >
> > SELECT login, SUM( hours ) AS time, MAX( [at] task :=
> > IF (
> > [at] prev_login = login, CONCAT_WS( ',', [at] task , task ) , task )
> > ) AS task
> > FROM activities
> > WHERE login = '%s'
> > AND date = '%s'
> > GROUP BY login
> > LIMIT 0 , 30
>
>
> Thanks, I will try this query, if you have a spare time, can you
> explain me this query?
> There are things that i don't understand like the first line and the
> use of ':=' and ' [at] '
>
>
> stefano

This should shed some light on it:

http://dev.mysql.com/doc/refman/5.0/en/user-variables.html
zac.carey [ Do, 26 Oktober 2006 20:26 ] [ ID #1514331 ]
Datenbanken » mailing.database.mysql » merging two querys

Vorheriges Thema: Trying to retrieve most recent record per date
Nächstes Thema: Parameters in MySQL