473,395 Members | 1,474 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,395 software developers and data experts.

question about synchronising results from 2 queries

Dears
I have the following problem

I’m using a query to get all the data from my database from the past
year

the second query is displaying the results by month.
How can I match the second query with the first query in order to get
the results from the same store on the same row?

example :
Ford got $2000,- in January and in February they earned $3000,-
BMW got $15000 in January and $7500 in February

in this example FORD AND BMW are the results from Query 1 and the
amounts mentioned are the results of Query 2. How can I print these
results on in the same row where I Ford or BMW is displayed?
thanks for your coop and feedback

Paul

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-synchron...ict142196.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=475576
Jul 17 '05 #1
6 1680
paulus4605 wrote:
Dears
I have the following problem

I’m using a query to get all the data from my database from the past
year

the second query is displaying the results by month.
How can I match the second query with the first query in order to get
the results from the same store on the same row?

example :
Ford got $2000,- in January and in February they earned $3000,-
BMW got $15000 in January and $7500 in February

in this example FORD AND BMW are the results from Query 1 and the
amounts mentioned are the results of Query 2. How can I print these
results on in the same row where I Ford or BMW is displayed?
thanks for your coop and feedback

Paul


without knowing your table definitions or the two queries, it is a bit difficult
to make suggestions, You can use left outer joins or "normal" joins depending
on lots of things...

table 1
id name
1 Ford
2 BMW

table2
id date amount
1 1/1/2004 1000
1 1/2/2004 1000
2 1/1/2004 500
2 1/2/2004 7000
1 2/3/2004 1000
2 2/9/2004 5000

select a.name as name, sum(b.amount) as jan,
sum(c.amount) as feb,
sum(d.amount) as mar....
from table1 a
left outer join table2 b on a.id = b.id
and extract(year from date) = '2004' and extract(MONTH from date) = '1'
left outer join table2 c on a.id = c.id
and extract(year from date) = '2004' and extract(MONTH from date) = '2'
left outer join table2 d on a.id = d.id
and extract(year from date) = '2004' and extract(MONTH from date) = '3'
.....
group by name, jan, feb, mar,....;

YMMV and you may need to tweak the syntax a bit... but should produce the output

name jan feb mar apr ....
FORD 1000 5000 3000
BMW 3000 7500 .....

Then using PHP you can add the "wording" if you want...

--
Michael Austin.
Consultant - Not Available.
Donations still welcomed. Http://www.firstdbasource.com/donations.html
:)
Jul 17 '05 #2
Michael
thanks for your reply

the queries look like this

$Year ="SELECT DISTINCT DEALER_REM FROM ELEC_REM_NOTE WHERE
CURRENT_MONTH LIKE "%2004" GROUP BY DEALER_REM";

the second QUERY = $Month =" SELECT DISTINCT DEALER_REM WHERE
CURRENT_MONTH =’JAN2004’ AND BLOC_ID IN (1,2,3,4,5,7,8,10,12) group by
DEALER_REM

thanks for your feedback

Paul

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-synchron...ict142196.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=476061
Jul 17 '05 #3
paulus4605 wrote:
Michael
thanks for your reply

the queries look like this

$Year ="SELECT DISTINCT DEALER_REM FROM ELEC_REM_NOTE WHERE
CURRENT_MONTH LIKE "%2004" GROUP BY DEALER_REM";

the second QUERY = $Month =" SELECT DISTINCT DEALER_REM WHERE
CURRENT_MONTH =’JAN2004’ AND BLOC_ID IN (1,2,3,4,5,7,8,10,12) group by
DEALER_REM
and what column (field) contains the Amount information - you are not selecting
it... You have not selected it. The table that contains the dealer id should be
unique and therefore not require a DISTINCT clause. the 2nd query also does not
contain a table name.

show me the output of the describe for table1 and table2.



thanks for your feedback
You're welcome...
Paul

--
Michael Austin.
Consultant - Available.
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)
Jul 17 '05 #4
"Michael Austin" wrote:
paulus4605 wrote:

<font color=purple>*> Michael</font>
<font color=purple>*> thanks for your reply</font>
<font color=purple>*> </font>
<font color=purple>*> the queries look like this </font>
<font color=purple>*> </font>
<font color=purple>*> $Year ="SELECT DISTINCT DEALER_REM
FROM ELEC_REM_NOTE WHERE</font>
<font color=purple>*> CURRENT_MONTH LIKE "%2004" GROUP BY
DEALER_REM";</font>
<font color=purple>*> </font>
<font color=purple>*> the second QUERY = $Month =" SELECT
DISTINCT DEALER_REM WHERE</font>
<font color=purple>*> CURRENT_MONTH =’JAN2004’ AND
BLOC_ID IN (1,2,3,4,5,7,8,10,12) group by</font>
<font color=purple>*> DEALER_REM</font>

and what column (field) contains the Amount information - you
are not selecting
it... You have not selected it. The table that contains the
dealer id should be
unique and therefore not require a DISTINCT clause. the 2nd
query also does not
contain a table name.

show me the output of the describe for table1 and table2.
<font color=purple>*> </font>
<font color=purple>*> </font>
<font color=purple>*> </font>

<font color=purple>*> thanks for your feedback</font>

You’re welcome...
<font color=purple>*> </font>
<font color=purple>*> Paul</font>
<font color=purple>*> </font>
--
Michael Austin.
Consultant - Available.
Donations welcomed.
Http://www.firstdbasource.com/donations.html
:)


oeps stupid of me

the both tables that I use are "FROM ELEC_REM_NOTE"

so the first query is $Year ="SELECT DISTINCT DEALER_REM FROM
ELEC_REM_NOTE WHERE CURRENT_MONTH LIKE"%2004" GROUP BY DEALER_REM";

the second query looks like this
$MONTH = "SELECT DISTINCT DEALER_REM ,SUM(TOTAL_REM_AMOUNT) FROM
ELEC_REM_NOTE WHERE CURRENT_MONTH =’JAN2004’ AND BLOC_ID IN
(1,2,3,4,5,7,8,10,12) GROUP BY DEALER_REM

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-synchron...ict142196.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=476807
Jul 17 '05 #5
"Michael Austin" wrote:
paulus4605 wrote:

<font color=purple>*> Michael</font>
<font color=purple>*> thanks for your reply</font>
<font color=purple>*> </font>
<font color=purple>*> the queries look like this </font>
<font color=purple>*> </font>
<font color=purple>*> $Year ="SELECT DISTINCT DEALER_REM
FROM ELEC_REM_NOTE WHERE</font>
<font color=purple>*> CURRENT_MONTH LIKE "%2004" GROUP BY
DEALER_REM";</font>
<font color=purple>*> </font>
<font color=purple>*> the second QUERY = $Month =" SELECT
DISTINCT DEALER_REM WHERE</font>
<font color=purple>*> CURRENT_MONTH =’JAN2004’ AND
BLOC_ID IN (1,2,3,4,5,7,8,10,12) group by</font>
<font color=purple>*> DEALER_REM</font>

and what column (field) contains the Amount information - you
are not selecting
it... You have not selected it. The table that contains the
dealer id should be
unique and therefore not require a DISTINCT clause. the 2nd
query also does not
contain a table name.

show me the output of the describe for table1 and table2.
<font color=purple>*> </font>
<font color=purple>*> </font>
<font color=purple>*> </font>

<font color=purple>*> thanks for your feedback</font>

You’re welcome...
<font color=purple>*> </font>
<font color=purple>*> Paul</font>
<font color=purple>*> </font>
--
Michael Austin.
Consultant - Available.
Donations welcomed.
Http://www.firstdbasource.com/donations.html
:)


oeps stupid of me

the both tables that I use are "FROM ELEC_REM_NOTE"

so the first query is $Year ="SELECT DISTINCT DEALER_REM FROM
ELEC_REM_NOTE WHERE CURRENT_MONTH LIKE"%2004" GROUP BY DEALER_REM";

the second query looks like this
$MONTH = "SELECT DISTINCT DEALER_REM ,SUM(TOTAL_REM_AMOUNT) FROM
ELEC_REM_NOTE WHERE CURRENT_MONTH =’JAN2004’ AND BLOC_ID IN
(1,2,3,4,5,7,8,10,12) GROUP BY DEALER_REM

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-synchron...ict142196.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=476807
Jul 17 '05 #6
paulus4605 wrote:

<snip>
so the first query is $Year ="SELECT DISTINCT DEALER_REM FROM
ELEC_REM_NOTE WHERE CURRENT_MONTH LIKE"%2004" GROUP BY DEALER_REM";

the second query looks like this
$MONTH = "SELECT DISTINCT DEALER_REM ,SUM(TOTAL_REM_AMOUNT) FROM
ELEC_REM_NOTE WHERE CURRENT_MONTH =’JAN2004’ AND BLOC_ID IN
(1,2,3,4,5,7,8,10,12) GROUP BY DEALER_REM

Same as I previously described:

select a.name as name, sum(b.amount) as jan,
sum(c.amount) as feb,
sum(d.amount) as mar....
from table1 a
left outer join table1 b on a.name = b.name
and CURRENT_MONTH =’JAN2004’
AND BLOC_ID IN (1,2,3,4,5,7,8,10,12)
left outer join table1 c on a.name = c.name
and CURRENT_MONTH =’FEB2004’
AND BLOC_ID IN (1,2,3,4,5,7,8,10,12)
....
group by a.name, b.amount, c.amount, d.amount,,,,;
You should get the distinct names and sums for each month.

if you want to insert the actual text, then it gets a bit more conveluted and
may not fit on one line... If you are using PHP then display the results in a table

NAME JAN FEB MAR ...
FORD 2000 4000 ...
BMW 9000 3000 ...

--
Michael Austin.
Consultant -Not Available.
Donations still welcomed. Http://www.firstdbasource.com/donations.html
:)
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: justme | last post by:
Dears I have created the following page to display my data <head> <style type="text/css"> body, td, th, h1, h2 {font-family: sans-serif;} body, td, th {font-size: 100%;} a:link {...
8
by: Frnak McKenney | last post by:
Back when computer dinosaurs roamed the earth and the precursors to today's Internet were tiny flocks of TDMs living symbiotically with the silicon giants, tracking access to data processing...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
10
by: Michael C# | last post by:
OK, here's the deal. I have a small XML file that represents a small database table. I load it into a System.XML.XMLDocument. So far so good. I run an XPath query against it to retrieve all the...
5
by: jzlondon | last post by:
Hi, I have a question that I wonder if someone might be able to help me with... I have an application which handles real-time financial data from a third party source. The data comes in via...
0
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
18
by: Narshe | last post by:
I've been struggling with this for a while. I have a business entity Employee that has a Company entity attached to it. Ex: public class Compay{ // blah } public class Employee
1
by: Steve Marshall | last post by:
I'm very new to ASP.NET and I'm develooing an application with an SQL Server database behind it. I have a form where the user can search for records, and the summary results are shown in a...
1
by: STUFIX | last post by:
Hi, I need to change a field name in a table stored on a backend database that is used by various queries, forms, etc on the front end client via a linked table. I can't work out how to change...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.