Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
fenster89411
Starting Member
7 Posts |
Posted - 2009-10-24 : 08:23:23
|
| Hey Guys,This is my first post and could realy do with some advice/help.I have a table called reciepts.The table has individulal rows for items bought.each row holds the item and transaction number.Example:Transaction number Item2234 22234 12234 32234 62235 12236 82236 42237 2etcI need to know all people who bought 20 items or more in a single transaction.so the query would be select * from reciepts where the same transaction number => 20I would like the return to be just the transaction numbers who meet this criteria rather than displaying the full 20 or so rows.is this easy to achieve? Can anyone get me started on this?And I hope this makes sense...Thanks in advance.. |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-10-24 : 09:27:28
|
select TransNo from table group by TransNo having count(*) > 19 No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
fenster89411
Starting Member
7 Posts |
Posted - 2009-10-24 : 10:31:04
|
| Thanks WebFred works a charm. |
 |
|
|
fenster89411
Starting Member
7 Posts |
Posted - 2009-10-24 : 15:25:42
|
| Can anyone show me an example of adding an inner join using WebFreds query?The table reciepts also has a client number which can be joined to table clients.clientnumberwhen I try I get errors on the Group by part.Im just learning SQL Query so apologies for the lame questions... |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-10-25 : 11:01:53
|
select DISTINCTr.TransNo,c.what_column_everfromreciepts rjoin (select TransNo from table group by TransNo having count(*) > 19)dton dt.TransNo = r.TransNojoin clients con c.Clientnumber = r.Clientnumber No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
fenster89411
Starting Member
7 Posts |
Posted - 2009-10-26 : 05:38:46
|
Again I thank you! |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-10-26 : 05:59:18
|
welcome  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|