Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language 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 27th, 2005, 07:15 AM
Registered User
 
Join Date: Apr 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do you query for number of occurences?

My question is the following:
Consider the table:



ITEM WHOLESALE WHOLESALE+0.15
-------------- --------- --------------
TOMATOES .34 .49
TOMATOES .51 .66
BANANAS .67 .82
TURNIPS .45 .60
BANANAS .89 1.04
APPLES .23 .38


I need a query which retrieves only those ‘ITEM’s whose number of occurrences is more than one.



That is, if I run the query, I should get only TOMATOES and BANANAS and not the other things which have occurred only once.



Can you think it for me?



 
Old January 27th, 2005, 10:32 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

SELECT Item, Count(*) As TotalItem
FROM MyTable
Group By Item
Having Count(*) > 1





Similar Threads
Thread Thread Starter Forum Replies Last Post
Count unique occurences Umasriram2 Excel VBA 2 May 28th, 2008 05:10 AM
Count string occurences across recordset goldstein SQL Server 2005 1 July 9th, 2007 06:47 PM
Count all occurences of a character in a string thomaz C# 2 February 9th, 2007 01:52 PM
Auto Number query again Brendan Bartley Access 4 August 26th, 2006 06:09 AM
Need incrementing number in query Mitch SQL Language 3 March 1st, 2005 04:22 AM





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