Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 17th, 2007, 07:59 AM
Registered User
 
Join Date: Jan 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Basic SQL query

Hi I am just try to learn SQL could help me solving the below request

If you had a customer table that had the customer names and the state where they live, how would you find the number of customers that live in each state? How would you sort the states in Alphabetical order?

Thanks

 
Old January 17th, 2007, 08:51 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there...

well.. if you are trying to learn i will only point you in the right direction...

to order by column you use "ORDER BY"

and to count the number of ocurrencies you have to investigate about aggregate functions (SUM, COUNT,...) and "GROUP BY".

HTH

Gonzalo
 
Old January 18th, 2007, 04:39 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

When using GROUP BY, any counting, summing, averaging, et al., is started over and a new row is generated for each distinct value.
So if you had
Code:
[u]fldSTATE</u>
  WA
  GA
  OR
  GA
  OR
  then, with
Code:
SELECT   fldSTATE, COUNT(fldSTATE)
Code:
GROUP BY fldSTATE;
you would get:
Code:
fldSTATE  COUNT(fldSTATE)
--------  ---------------
  GA           2
  OR           2
  WA           1





Similar Threads
Thread Thread Starter Forum Replies Last Post
Another basic access query bunkerbang Access VBA 1 September 13th, 2007 06:38 AM
Visual basic update query barteksollie Access 1 August 7th, 2006 01:55 AM
Basic SQL Problem mattastic SQL Server 2000 4 December 8th, 2004 05:20 AM
SQL and Visual Basic mytreasure23 SQL Server 2000 1 November 9th, 2004 03:26 AM
Basic char array and cin query. gillianbc C++ Programming 4 November 4th, 2004 07:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.