473,569 Members | 2,593 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:
TblOrderRankTyp e
OrderRankTypeID
CustomerID
Rank
Type

I need help with two queries, please.

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

2. Count Customers(Custo merID) 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 1510
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:
TblOrderRankTyp e
OrderRankTypeID
CustomerID
Rank
Type 1. Count Customers(Custo merID) by Rank who placed Type 1 or Type 2 orders
and never placed a Type 3 order.

2. Count Customers(Custo merID) 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 tblOrderRankTyp e where Type = 3

then

qryHas1or2ButNo 3
select distinct CustomerId from tblOrderRankTyp e
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*****@earthl ink.net> wrote in message
news:sU******** *********@newsr ead3.news.atl.e arthlink.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:
TblOrderRankTyp e
OrderRankTypeID
CustomerID
Rank
Type

I need help with two queries, please.

1. Count Customers(Custo merID) 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(Custo merID) 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******@hotma il.com> wrote in message
news:2s******** *****@uni-berlin.de...
"Susan" <sm*****@earthl ink.net> wrote in message
news:sU******** *********@newsr ead3.news.atl.e arthlink.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:
TblOrderRankTyp e
OrderRankTypeID
CustomerID
Rank
Type

I need help with two queries, please.

1. Count Customers(Custo merID) 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(Custo merID) 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
3055
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 solve my problem. I'll turn to MySQL doc after getting through this pressing project. Thanks a lot Roger! Babale -----Urspr=FCngliche...
2
1647
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 doing a project of data mining, and I run a mysql database to store my data. the database structure:
2
1506
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" link(?). Sorry for repetition, but the story has developed a bit. We have an Access 2000 database application - reports distributor. Reports are created...
5
1911
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
2601
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 to run from VB. My pass-thru query retrieves data from our AS/400 that I use to build a local table (on my PC). My pass-thru and local do in fact...
3
10622
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 that are hard to find. The main problem I am having right now is that I have a report that is sorted by one of these lookup fields and it only displays...
2
1620
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. here's what i have. a table called "RESULTS" - this table has 4 columns i need to work with. CustID, Matrix, Test, Parameter. i have three...
0
2434
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 the whole. I really need MySQL wizz to give me a hand (and maybe refer me to books to get me to the wizz level myself). First off, english is a...
8
2378
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 sp_spaceused on it. The index_size was also pretty big in 6 digits. On looking at the tableA
1
2035
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 counts based on 3 different tables. For instance, I need to count the number of new clients enrolled in a program for a given month or year-to-date...
0
7614
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8125
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7676
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7974
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5219
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.