473,387 Members | 3,033 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,387 software developers and data experts.

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 1276

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: 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
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
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...
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...

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.