SQL Query - Need some basic help

Posted by Chuck Folds on Stack Overflow See other posts from Stack Overflow or by Chuck Folds
Published on 2010-04-02T21:49:38Z Indexed on 2010/04/02 21:53 UTC
Read the original article Hit count: 349

Filed under:
|

I'm in need of some basic TSQL help. Here's my table layout:

Orders Table

  • SSN
  • ZipCode

ZipLookup Table

  • ZipCode
  • State

All columns are varchars.

How would I get a list of States with the number of distinct SSN's in each state? Preferably, if a particular SSN has orders from multiple states only the state with the most orders would be counted for that SSN.

Thank you for any tips you can give me.

© Stack Overflow or respective owner

Related posts about sql

Related posts about tsql