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

Home Posts Topics Members FAQ

Trying to form these Queries

5 New Member
Hi all a bit new to this so here goes

I am trying to achive the following quiries in sql

total cost of the cars sold by each salesman in the past month I can only get it to show all the sales in the db in month order

add the commission earned by each salesman to the above report

outputs both the most expensive and least expensive car sold in the past month

and finaly

all car sales in the past month. Include salesperson number, salesperson name, customer number, customer name and customer address

meany thanks

Mike
Dec 11 '06 #1
3 1628
markmcgookin
648 Recognized Expert Contributor
Hi all a bit new to this so here goes

I am trying to achive the following quiries in sql

total cost of the cars sold by each salesman in the past month I can only get it to show all the sales in the db in month order

add the commission earned by each salesman to the above report

outputs both the most expensive and least expensive car sold in the past month

and finaly

all car sales in the past month. Include salesperson number, salesperson name, customer number, customer name and customer address

meany thanks

Mike
Hi Mike,

Seems simple enough, but can you post more details?

i.e. information about the tables that will be used. e.g. tableName{Field1 (PK), Field 2, Field 3} etc

Mark
Dec 11 '06 #2
mike2098
5 New Member
Hi Mike,

Seems simple enough, but can you post more details?

i.e. information about the tables that will be used. e.g. tableName{Field1 (PK), Field 2, Field 3} etc

Mark
Hi ok here are my table entries

Customer
Create Table Customer(
CustomerNo COUNTER Primary Key NOT NULL,
FirstName VarChar(50) not null,
LastName VarChar(50) not null,
Address VarChar(30),
Town VarChar(30),
Postcode VarChar(9),
Telephone VarChar(12)
)

Centre
Create Table Centre(
CentreNo COUNTER Primary Key NOT NULL,
Name varchar(40),
Address VarChar(30),
PostCode VarChar(30),
Telephone VarChar (20)
)

Sales Staff
Create Table SalesStaff(
SalespersonNo COUNTER Primary Key NOT NULL,
SalespersonName VarChar(40) not null,
CentreNo int,
Foreign Key (CentreNo) REFERENCES Centre(CentreNo)
)


Car Sale
Create Table CarSale(
CarReg VarChar(10) Primary Key NOT NULL,
CarPrice VarChar(10),
CarModel VarChar(20),
CarMake VarChar(10),
SalespersonNo int,
CustomerNo int,
SaleDate Date,
Foreign Key (SalespersonNo) REFERENCES SalesStaff (SalespersonNo),
Foreign Key (CustomerNo) REFERENCES Customer(CustomerNo)
)

commission

Car Price(£) % Commission
0-5000 2
5000-10000 3
10000-15000 4
15000+ 5


and these are the queries I need to get from them

total cost of the cars sold by each salesman in the past month (For example: S1 has sold R123 JKN £6,500
X567 JMK £10,100
therefore the output would be S1 16,600)

add the commission earned by each salesman to the above report

outputs both the most expensive and least expensive car sold in the past month

and finally

all car sales in the past month. Include salesperson number, salesperson name, customer number, customer name and customer address in your output. Order by salesperson number.


thanks in advance

Mike
Dec 11 '06 #3
mike2098
5 New Member
Hi ok here are my table entries

Customer
Create Table Customer(
CustomerNo COUNTER Primary Key NOT NULL,
FirstName VarChar(50) not null,
LastName VarChar(50) not null,
Address VarChar(30),
Town VarChar(30),
Postcode VarChar(9),
Telephone VarChar(12)
)

Centre
Create Table Centre(
CentreNo COUNTER Primary Key NOT NULL,
Name varchar(40),
Address VarChar(30),
PostCode VarChar(30),
Telephone VarChar (20)
)

Sales Staff
Create Table SalesStaff(
SalespersonNo COUNTER Primary Key NOT NULL,
SalespersonName VarChar(40) not null,
CentreNo int,
Foreign Key (CentreNo) REFERENCES Centre(CentreNo)
)


Car Sale
Create Table CarSale(
CarReg VarChar(10) Primary Key NOT NULL,
CarPrice VarChar(10),
CarModel VarChar(20),
CarMake VarChar(10),
SalespersonNo int,
CustomerNo int,
SaleDate Date,
Foreign Key (SalespersonNo) REFERENCES SalesStaff (SalespersonNo),
Foreign Key (CustomerNo) REFERENCES Customer(CustomerNo)
)

commission

Car Price(£) % Commission
0-5000 2
5000-10000 3
10000-15000 4
15000+ 5


and these are the queries I need to get from them

total cost of the cars sold by each salesman in the past month (For example: S1 has sold R123 JKN £6,500
X567 JMK £10,100
therefore the output would be S1 16,600)

add the commission earned by each salesman to the above report

outputs both the most expensive and least expensive car sold in the past month

and finally

all car sales in the past month. Include salesperson number, salesperson name, customer number, customer name and customer address in your output. Order by salesperson number.


thanks in advance

Mike

I have tried
SELECT [CarSale].[SaleDate] AS [SaleDate By Month], CarSale.SalespersonNo, Sum(CarSale.CarPrice) AS [Sum Of CarPrice]
FROM CarSale
WHERE SaleDate >= 01/12/2006
GROUP BY [CarSale].[SaleDate], CarSale.SalespersonNo, [CarSale].[SaleDate], [CarSale].[SaleDate];

but it just lists all months not just the last one ?
Dec 11 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tom Cusick | last post by:
MS Access Version 2002 (10.4302.4291) SP-2 Windows XP Pro 2002 SP-1 ----------------------------------------------------------------- Ok my question is this. I have one form laid out the way I...
4
by: intl04 | last post by:
How do I create a data input form in Access that is external to the Access database to which it's connected (if that's possible, which I believe it is)? For example, if someone clicks on an Access...
1
by: Jeremy Campbell | last post by:
I am creating a master form that users can hit a command button to direct them to a form of their choice. How can I link to the seperate databases where the forms are stored. Each form might have...
4
by: deko | last post by:
I'm a little nervous about slamming my database with a dozen Update queries in a loop that all modify RecordSources of open forms. Will the use of DoEvents and/or a Sleep function ameliorate any...
10
by: glenn354 | last post by:
I have a form I would like to use in front of several queries. For example, I want to use frmA but only looking at the records retrieved by qryX. Then I want to use frmA again, but only looking at...
5
by: EricS | last post by:
Hi, Was wondering if anyone can help. I have multiple queries in a database. The selection criteria for these queries is always a time period I want to do the analysis by. Rather than having to go...
1
by: bgreenspan | last post by:
Hi Everyone, I'm back for some more expert help. Here's what I am doing and what I tried. My database has entries with Contract Names and Expiry Dates, among other fields. I have a form...
46
by: dude88888 | last post by:
Hello I have one query where i get the total number of units for an entire fund say fund 89 has 1000 total units Then i need to find out how much of the total fund each user has say user...
10
by: RLN | last post by:
I have 4 queries and all 4 queries use different tables and pull different columns. Is it possible to have one Generic all Purpose form (frmGeneral) and on the fly at run time set frmGeneral's...
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...
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
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
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 ...
1
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.