469,900 Members | 1,442 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,900 developers. It's quick & easy.

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

Oct 24 '06 #1
6 2952

st*************@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?

Oct 24 '06 #2

st*************@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

Oct 24 '06 #3

strawberry wrote:
st*************@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

Oct 25 '06 #4

st*************@gmail.com wrote:
strawberry wrote:
st*************@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 @prev_login := NULL ;

SELECT login, SUM( hours ) AS time, MAX( @task :=
IF (
@prev_login = login, CONCAT_WS( ',', @task , task ) , task )
) AS task
FROM activities
WHERE login = '%s'
AND date = '%s'
GROUP BY login
LIMIT 0 , 30

Oct 25 '06 #5

strawberry wrote:
st*************@gmail.com wrote:
strawberry wrote:
st*************@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 @prev_login := NULL ;

SELECT login, SUM( hours ) AS time, MAX( @task :=
IF (
@prev_login = login, CONCAT_WS( ',', @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 '@'
stefano

Oct 26 '06 #6

st*************@gmail.com wrote:
strawberry wrote:
st*************@gmail.com wrote:
strawberry wrote:
st*************@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 @prev_login := NULL ;

SELECT login, SUM( hours ) AS time, MAX( @task :=
IF (
@prev_login = login, CONCAT_WS( ',', @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 '@'
stefano
This should shed some light on it:

http://dev.mysql.com/doc/refman/5.0/...variables.html

Oct 26 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Josué Maldonado | last post: by
3 posts views Thread by Patrick | last post: by
2 posts views Thread by holding1 | last post: by
2 posts views Thread by Dave Taylor | last post: by
6 posts views Thread by Fuzzydave | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.