473,386 Members | 1,679 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.

Query writing help

Hello,

Please can you help me.

The Booking Detail table shows each leg of a journey. BookingRef 1 is
a booking for an adult and a child to fly from London to Paris and
return. BookingRef 2 is a booking for an Adult to fly from London to
New York via Paris and then return. PassType A is an Adult ticket and
PassType C is a Child ticket.

Bookings Detail Table

BookingRef Depart Arrive PassType Revenue
1 L P A 10
1 P L A 15
1 L P C 10
1 P L C 20
2 L P A 10
2 P L A 15
2 P N A 30
2 N P A 35

Want I want to end up with is a report of the revenues earned on each
return journey (ie London to Paris = 80, Paris to New York = 65).

I thought of doing it this way but I'm sure there are alternatives.

I need a way for the query to recognise that a record with Depart = L,
Arrive = P is the same journey as a Depart = P, Arrive = L and then
combine these records into one and add the revenues. The result of the
query should look like this

BookingRef Depart Arrive PassType Revenue
1 L P A 25
1 L P C 30
2 L P A 25
2 P N A 65

I would then put the results of this query into Excel for PivotTable
analysis giving

Depart Arrive Revenue
L P 80
P N 65
Nov 13 '05 #1
2 1589
Jamie wrote:
Hello,

Please can you help me.

The Booking Detail table shows each leg of a journey. BookingRef 1 is
a booking for an adult and a child to fly from London to Paris and
return. BookingRef 2 is a booking for an Adult to fly from London to
New York via Paris and then return. PassType A is an Adult ticket and
PassType C is a Child ticket.

Bookings Detail Table

BookingRef Depart Arrive PassType Revenue
1 L P A 10
1 P L A 15
1 L P C 10
1 P L C 20
2 L P A 10
2 P L A 15
2 P N A 30
2 N P A 35

Want I want to end up with is a report of the revenues earned on each
return journey (ie London to Paris = 80, Paris to New York = 65).

I thought of doing it this way but I'm sure there are alternatives.

I need a way for the query to recognise that a record with Depart = L,
Arrive = P is the same journey as a Depart = P, Arrive = L and then
combine these records into one and add the revenues. The result of the
query should look like this

BookingRef Depart Arrive PassType Revenue
1 L P A 25
1 L P C 30
2 L P A 25
2 P N A 65

I would then put the results of this query into Excel for PivotTable
analysis giving

Depart Arrive Revenue
L P 80
P N 65


I would consider adding another field...Leg. Then you could sequence them.

Not all round trips are point A to B B To A. Amsterdam To Paris. Paris
To Rome. Rome To Amsterdam is an example. You might have someone take
off from Paris To London then decide to take a train back or perhaps a car.

IOW, you might want to know which is the initial starting record and
which is the ending record.

Nov 13 '05 #2
Thanks for the reply salad,

Here is more explaination about the problem.

If a journey goes A to B then B to C Then C to B Then B to A i want to
add together the records for A to B with B to A and B to C with C to A
giving two return legs of the journey. Im not interested in finding A
to C then C to A. If a journey only goes A to B and no return then
this should be put in a new record for A to B and then counted with
all the other A to B (and return) records.

Unfortunatly i do not have the authority to add fields to the database
so i have to work with what i have got.

Any further answers much appreciated.

Jamie

Salad <oi*@vinegar.com> wrote in message news:<Zy******************@newsread2.news.pas.eart hlink.net>...
Jamie wrote:
Hello,

Please can you help me.

The Booking Detail table shows each leg of a journey. BookingRef 1 is
a booking for an adult and a child to fly from London to Paris and
return. BookingRef 2 is a booking for an Adult to fly from London to
New York via Paris and then return. PassType A is an Adult ticket and
PassType C is a Child ticket.

Bookings Detail Table

BookingRef Depart Arrive PassType Revenue
1 L P A 10
1 P L A 15
1 L P C 10
1 P L C 20
2 L P A 10
2 P L A 15
2 P N A 30
2 N P A 35

Want I want to end up with is a report of the revenues earned on each
return journey (ie London to Paris = 80, Paris to New York = 65).

I thought of doing it this way but I'm sure there are alternatives.

I need a way for the query to recognise that a record with Depart = L,
Arrive = P is the same journey as a Depart = P, Arrive = L and then
combine these records into one and add the revenues. The result of the
query should look like this

BookingRef Depart Arrive PassType Revenue
1 L P A 25
1 L P C 30
2 L P A 25
2 P N A 65

I would then put the results of this query into Excel for PivotTable
analysis giving

Depart Arrive Revenue
L P 80
P N 65


I would consider adding another field...Leg. Then you could sequence them.

Not all round trips are point A to B B To A. Amsterdam To Paris. Paris
To Rome. Rome To Amsterdam is an example. You might have someone take
off from Paris To London then decide to take a train back or perhaps a car.

IOW, you might want to know which is the initial starting record and
which is the ending record.

Nov 13 '05 #3

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

Similar topics

20
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
4
by: George Stout | last post by:
First off I do not know alot about writing queries to an Access Database from an ASP page. This is why I need help. I have an Events database for 6 colleges in our metro area. On the homepage I...
7
by: Simon Bailey | last post by:
How do you created a query in VB? I have a button on a form that signifies a certain computer in a computer suite. On clicking on this button i would like to create a query searching for all...
8
by: Adam Louis | last post by:
I would like help resolving this problem. I'm a novice who's been hired to query a hospital database and extract useful information, available to me only in a dynamically generated, downloadable...
6
by: Martin Lacoste | last post by:
Ok, before I headbutt the computer... don't know why when I add criteria in a query, I get an 'invalid procedure call'. I also don't know why after searching the help in access, the various access...
2
by: Fendi Baba | last post by:
I created a person table with various fields such as Suffix, Salutation, etc, Some of these fields may not be mandatory for example suffix. In the actual table itself, I only have a field for...
2
by: mmitchell_houston | last post by:
I'm working on a .NET project and I need a single query to return a result set from three related tables in Access 2003, and I'm having trouble getting the results I want. The details: ...
4
by: MCLR | last post by:
Good day to all: I found your website a couple of days ago as I was searching for resources that can help within my particular problem in writing a script for an Access Query. The issue is to...
16
by: laverdir | last post by:
<? $query = "SELECT " . $this->tabela3 . ".id, " . $this->tabela3 . ".naziv, " . $this->tabela3 . ".spisatelj, " . $this->tabela3 . ".najava, " . " DATE_FORMAT(" . $this->tabela3 ....
2
by: mary mathews | last post by:
is there any way to change the position of a column in a table by writing sql query? for eg; Table 'demo' contains 3 fields: companyName EmpName id I need to move the 'id' from last...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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...
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
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.