473,473 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

sql join query

We have the three tables below and for each customer, we need the
following information;

Result expected:

Month | Sales total | Payment | Oustanding

Jan | 1200.99 | 200.99 | 1000
Feb | 0.00 | 1000.00 | 0
Can anyone help out with the sql query to generate this.

Thanks

Barry

CREATE TABLE `order_details` (
`order_details_id` int(50) NOT NULL auto_increment,
`order_id` varchar(255) NOT NULL default '',
`product_id` varchar(255) NOT NULL default '',
`quantity` decimal(11,2) NOT NULL default '0.00',
`rate` decimal(11,2) NOT NULL default '0.00',
`datecreated` date default '0000-00-00',
PRIMARY KEY (`order_details_id`),
UNIQUE KEY `order_details_id` (`order_details_id`),
KEY `order_details_id_idx` (`order_details_id`),
KEY `order_id_idx` (`order_id`)
) TYPE=MyISAM;

CREATE TABLE `orders` (
`orderid` int(11) NOT NULL auto_increment,
`invoice_id` varchar(255) NOT NULL default '',
`page_no` varchar(255) NOT NULL default '',
`custid` varchar(255) NOT NULL default '',
`driver_id` varchar(255) NOT NULL default '',
`datecreated` date NOT NULL default '0000-00-00',
PRIMARY KEY (`orderid`),
UNIQUE KEY `orderid` (`orderid`),
KEY `orders_id_idx` (`orderid`),
KEY `orders_invoice_id_idx` (`invoice_id`)
) TYPE=MyISAM;

CREATE TABLE `payment` (
`payment_id` int(11) NOT NULL auto_increment,
`payment_amount` decimal(11,2) NOT NULL default '0.00',
`payment_date` date default NULL,
`payment_method` varchar(25) default NULL,
`custid` int(11) NOT NULL default '0',
`driver_id` varchar(255) default NULL,
`inv_id` varchar(255) NOT NULL default '0',
`page_no` int(11) NOT NULL default '0',
PRIMARY KEY (`payment_id`),
UNIQUE KEY `payment_id` (`payment_id`),
KEY `payment_id_idx` (`payment_id`)
) TYPE=MyISAM;
Jul 19 '05 #1
0 1343

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

Similar topics

0
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would have passed it, because your queries did help me...
12
by: Phil Powell | last post by:
<cfquery name="getAll" datasource="#request.dsn#"> SELECT U.userID, U.fname, U.lname, U.phone, U.lastLoggedIn, U.choiceId, U.experience, T.label AS teamLabel, R.label AS roleLabel FROM User U...
5
by: jason.evans | last post by:
Hi there. I am having an intrigueing problem. I have a query which left joins another query to itself twice. The original query is derived from a linked table in SQLServer 2000. When I run...
14
by: Jim Andersen | last post by:
I have a problem with this standard employee-supervisor scenario For pictures: http://www.databasedev.co.uk/self-join_query.html I want to show all employees "belonging" to a specific...
6
by: dmonroe | last post by:
hi group -- Im having a nested inner join problem with an Access SQl statement/Query design. Im running the query from ASP and not usng the access interface at all. Here's the tables: ...
0
by: mlarson | last post by:
I have a program that worked fine then they needed to be able to also see the empty cells (inmate cells) on a housing unit when they ran the query. So what I had to do was take two tables and...
3
by: Zeff | last post by:
Hi all, I have a relational database, where all info is kept in separate tables and just the id's from those tables are stored in one central table (tblMaster)... I want to perform a query, so...
12
by: Chamnap | last post by:
Hello, everyone I have one question about the standard join and inner join, which one is faster and more reliable? Can you recommend me to use? Please, explain me... Thanks Chamnap
3
by: nico3334 | last post by:
I currently have a query that Joins 2 Tables (Table1 and Table2) using LEFT OUTER JOIN. Here is an example of that query: SELECT a.supply, a.state, b.cost FROM Table1 a LEFT...
2
theGeek
by: theGeek | last post by:
I always wonder which one of join or subquery should I be using to solve a particuar problem so that I get the correct result set in minimum time. It usually happens that I can write a query quickly...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.