473,320 Members | 2,092 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,320 software developers and data experts.

Need Help With Two Queries

Customer Orders are ranked from 1 to 10 and are assigned an order type of 1,
2 or 3. The table for this is:
TblOrderRankType
OrderRankTypeID
CustomerID
Rank
Type

I need help with two queries, please.

1. Count Customers(CustomerID) by Rank who placed Type 1 or Type 2 orders
and never placed a Type 3 order.

2. Count Customers(CustomerID) by Rank who placed all Type 3 orders and
never placed a Type 1 or Type 2 order.

I'm having problems excluding Type 3 in 1 and excluding Type 1 or Type 2 in
2.

Thank you!

Susan
Nov 13 '05 #1
3 1499
Susan wrote:
Customer Orders are ranked from 1 to 10 and are assigned an order type of 1,
2 or 3. The table for this is:
TblOrderRankType
OrderRankTypeID
CustomerID
Rank
Type 1. Count Customers(CustomerID) by Rank who placed Type 1 or Type 2 orders
and never placed a Type 3 order.

2. Count Customers(CustomerID) by Rank who placed all Type 3 orders and
never placed a Type 1 or Type 2 order.

I'm having problems excluding Type 3 in 1 and excluding Type 1 or Type 2 in
2.

You might be able to do each one of these queries in a single step, but
I prefer to keep things simple, both for myself and for those who might
come after me.

I would do both of these queries in two stages. IE - for #1, do this first:

qryHasType3
select distinct CustomerId from tblOrderRankType where Type = 3

then

qryHas1or2ButNo3
select distinct CustomerId from tblOrderRankType
where (Type = 1 or Type = 2) and
CustomerID not in (select CustomerId from qryHasType3)

The second one should follow easily for you.

Nov 13 '05 #2
"Susan" <sm*****@earthlink.net> wrote in message
news:sU*****************@newsread3.news.atl.earthl ink.net...
Customer Orders are ranked from 1 to 10 and are assigned an order type of
1,
2 or 3. The table for this is:
TblOrderRankType
OrderRankTypeID
CustomerID
Rank
Type

I need help with two queries, please.

1. Count Customers(CustomerID) by Rank who placed Type 1 or Type 2
orders
and never placed a Type 3 order.
something like this (air code)

select c.custRank, count(*) as customerCount
from customers as c
where
(c.custType = 1 or c.custType = 3)
and not exists
(
select * from customers as c2
where c2.customerID = c.customerID
and c2.custType = 3
)
group by c.custRank
order by c.custRank
You can use the same logic for the second query. You'll need to substitute
your own table / column names as well.

2. Count Customers(CustomerID) by Rank who placed all Type 3 orders and
never placed a Type 1 or Type 2 order.

I'm having problems excluding Type 3 in 1 and excluding Type 1 or Type 2
in
2.

Thank you!

Susan

Nov 13 '05 #3
John,

Thank you very much for your response!

Is that a typo in the first Where clause - should the second Type be 2 not
3? Also, directly following did you mean by Not Exists Not In?

I tried your SQL and it doesn't quite work the way I need. Some customers
place some orders of Type 1 and other orders of Type 2. I need these
customers to be counted once. Some customers place Type 1 orders, some Type
2 orders and other customers sometimes Type 1 and other times Type 2. Your
SQL counts the latter customers twice. Can you suggest a revised SQL.

Thanks, John!

Susan
"John Winterbottom" <as******@hotmail.com> wrote in message
news:2s*************@uni-berlin.de...
"Susan" <sm*****@earthlink.net> wrote in message
news:sU*****************@newsread3.news.atl.earthl ink.net...
Customer Orders are ranked from 1 to 10 and are assigned an order type of 1,
2 or 3. The table for this is:
TblOrderRankType
OrderRankTypeID
CustomerID
Rank
Type

I need help with two queries, please.

1. Count Customers(CustomerID) by Rank who placed Type 1 or Type 2
orders
and never placed a Type 3 order.


something like this (air code)

select c.custRank, count(*) as customerCount
from customers as c
where
(c.custType = 1 or c.custType = 3)
and not exists
(
select * from customers as c2
where c2.customerID = c.customerID
and c2.custType = 3
)
group by c.custRank
order by c.custRank
You can use the same logic for the second query. You'll need to substitute
your own table / column names as well.

2. Count Customers(CustomerID) by Rank who placed all Type 3 orders and
never placed a Type 1 or Type 2 order.

I'm having problems excluding Type 3 in 1 and excluding Type 1 or Type 2
in
2.

Thank you!

Susan


Nov 13 '05 #4

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...
2
by: Alexandre MELARD | last post by:
Hi, My name is alexandre, I am 4th year student at the Napier university of edinburgh. I am finishing my year and do a presentation of my honours project next wednesday (the 5th of May). I am...
2
by: Galina | last post by:
Hello I already initiated a thread with the same name on 22/03/2004. Thank you everyone who answered me. I wanted to link to that thread, but somehow there was no "Post follow on article"...
5
by: Alicia | last post by:
Hello everyone based on the data, I created a union query which produces this. SELECT ,,, 0 As ClosedCount FROM UNION SELECT ,, 0 AS OpenedCount, FROM ORDER BY , ;
8
by: Tcs | last post by:
I've been stumped on this for quite a while. I don't know if it's so simple that I just can't see it, or it's really possible. (Obviously, I HOPE it IS possible.) I'm trying to get my queries...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
2
by: rockyptc | last post by:
greetings. first, i apologize for asking an old question. it appears that i'm looking for a solution that was already given but it don't seem to fit my scenario. so thanks for putting up with me. ...
0
by: Chuck36963 | last post by:
Hi all, I've been working on a listing problem and I can't figure out how to work it out. I have looked far and wide on the web to find answers, but I'd like other peoples input on my project in...
8
by: rshivaraman | last post by:
Hi : I have a TableA with around 10 columns with varchar and numeric datatypes It has 500 million records and its size is 999999999 KB. i believe it is kb i got this data after running...
1
by: mskapek | last post by:
I need some advise on how to best create an Access 2002 report from multiple "total" queries, each which result in 3- 5 values that I need displayed on my report. Most of the queries do simple...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.