473,394 Members | 1,800 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,394 software developers and data experts.

Query with Counts Help...

Hello All,

I need help with a SQL Query.

I have a table with a StateId and PartNumber. I'll be joining some tables to get the state name from the StateId and Part Description from the Part Number.

Where I need the help is from the original table. What I have to do is list the part and quantity sold in each state.

I might have something like...

StateId PartNumber
19 123
18 456
19 123
18 789

I need a query to get the counts for each part in each state so I get something like...

19 123 2
18 456 1
18 789 1

So after all my joins and stuff I would get
Arkansas Misc Part Example Description 2
Alabama Another Part Example 1
Alabama My Test Part Description 1

After all is said and done, I'll sort by state then by description.....

Alabama Another Part Example 1
Alabama My Test Part Description 1
Arkansas Misc Part Example Description 2

I think I can join to get the state names and part descriptions, but I don't know how to get the counts appropriately.

Any help would be greatly appreciated!

Thanks!
May 17 '09 #1
2 1359
ck9663
2,878 Expert 2GB
follow this code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. select stateneme, partdescription, count(*)
  3. from YourMainTable M
  4. left join YourStateTable  st on st.stateid = m.stateid
  5. left join YourPartTable pt on pt.partnumber = m.partnumber
  6. group by statename, partdescription
  7. order by 2
  8.  
  9.  
I don't mean that you follow it literally. Just follow the logic.

Happy Coding!

--- CK
May 18 '09 #2
Thanks! That Helped!!
May 21 '09 #3

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

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?
7
by: jane | last post by:
HI, I was ask to do a query to get the member active condition I had table to show the member number and active status in three month. ACC A1 A2 A3 ---- -----------...
1
by: Randy K | last post by:
I have a table with some 35000 records and I need some help sorting it out. The goal is to get counts of failures modes oraganized by serial number. the table is set up roughly like this. s/n ...
1
by: sunilkeswani | last post by:
Hi I am still new to access. I want to know how i can build a query which can display results from 4 different columns/fields Like. Field1 Field2 Field3 Field4 1 2 1 ...
3
by: Bill Hutchison | last post by:
I have a query that returns different results (3508 rows for snapshot, 6288 for dynaset) and that is the only thing I change to get the different results. When I try to make a table from the...
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...
2
by: runway27 | last post by:
hi i have an enquiry table which collects information about users making an online travel enquiry the fields in the table are = StoryTitle, EndCity, mode, PricedFrom, numAdults, numChildren,...
1
by: j420exe | last post by:
I have 3 tables: ARTISTS, ART and PAINTINGS ARTISTS has columns (data): userid (adam, betty, gil, jack, larry, steve, tyler) full_name (firstname lastname) ART has columns: art_id (auto number...
9
by: ncyankeefan | last post by:
I am trying to get the number of specific alerts for each month of the year. I would like to get these counts in one query or subquery. There is a date field in table so I can specifically get the...
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: 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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...

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.