473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 3049

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brian | last post by:
Hello I am using version 4.0.12-nt of MySQL and when I hit the enter key rapidly I can't connect to the database. The result is a message is returned to me from mysql that says I can't connect...
1
by: Josué Maldonado | last post by:
Hello list, I have a table with an index in a foreing key field (int4), if I do select from pedido where prvdfk=3, explain says is using seq scan to access it. I noticed all my querys runs in...
3
by: Patrick | last post by:
I have got 2 XML documents, both of which conform to the same XSD Schema, which define possible optional elements. The 2 XML documents contain 2 disjoint set of XML elements. What is the best,...
0
by: George | last post by:
Hi, The storeprocedure fails with null exception on the DB2 development centre for SELECT querys for all tables that has the number of columns greater than 10. Strange ,but true ..i reinstalled...
2
by: holding1 | last post by:
Hi there. Somebody has been inputing data into an old backup database instead of the current one. What is the easiest way to move or merge that data into the current one? H1
1
by: svdh | last post by:
I have posed a question last saturday and have advanced alot in the meantime. But I am still not there Problem is that I try to merging various fields from various tables in one document in Word...
2
by: Dave Taylor | last post by:
Is there a decent explanation of how menu merging with MDI forms work in VB.NET? I've read through the online help and it still seems that whenever I change menus around or whatever, it breaks...
3
by: Chifo | last post by:
hello. i have a problem with a populate html table with data from table here it's the problem two querys retrieving data from table, one of querys show me a colletion of data from 6:00 am to...
6
by: Fuzzydave | last post by:
I am back developing futher our Python/CGI based web application run by a Postgres DB and as per usual I am having some issues. It Involves a lot of Legacy code. All the actual SQL Querys are...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.