Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can Somebody help me solve this?

Status
Not open for further replies.

DaCD

Programmer
Feb 19, 2006
1
US
PERSON
OID_PERSON

PREFIX
FIRSTNAME
LASTNAME
SUFFIX
GENDER




ADDRESS
OID_ADDRESS

OID_PERSON (FK)
ADDRESS1
ADDRESS2
CITY
STATE
ZIP
PLUS4


TRANSACTIONS
OID_TRANSACTION

OID_PERSON (FK)
TRANSACTION_DATE
TRANSACTION_AMOUNT
TRANSACTION_TYPE





With SQL, how can you return FirstName, LastName and Address components for records with the LastName of “Jackson” and the zip of 75063?


With SQL, how can you identify the Person with the largest total amount of money spent and return their FirstName, LastName, Address components, and the total amount of all their transactions?


With SQL, how can you identify the Person with the most purchase transactions and return their FirstName, LastName, Address components, and the number of transactions they have made?
 
This should work for your first question:

Select

p.FirstName,
p.LastName,
a.Address1,
a.Address2,
a.city,
a.zip,
a.plus4

From
Person p left join Address a on (p.OID_Person = a.OID_Person)

where
p.LastName = 'Jackson' and a.Zip = '75063'
 
As for the 2nd question Start it nearly the same only this time use Tranactions t
and in the select statement do a sum(t.TRANSACTION_AMOUNT)total
You also could do a order by total Desc:
which will show everyone but put the highest to the top

3rd Question
Is again like before only this time use count(t.OID_PERSON)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top