If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > cout() issue

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-26-09, 15:43
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
cout() issue

In this query I want the recordset to be empty if the count is more than ten. Other wise I want to know who many the count is.

SELECT pre_28_reg, count(*) AS count
FROM Meet_reg
WHERE pre_28_reg =2 AND count < 10
GROUP BY pre_28_reg

Nick
Reply With Quote
  #2 (permalink)  
Old 12-26-09, 16:30
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Quote:
Originally Posted by oldnickj
In this query I want the recordset to be empty if the count is more than ten. Other wise I want to know who many the count is.
This should work:
Code:
SELECT pre_28_reg, count(*) AS count
FROM Meet_reg
WHERE pre_28_reg = 2 
GROUP BY pre_28_reg
having count(*) <= 10
I can't see why you are selecting pre_28_reg as you know the value will be 2 but I left it in. I changed the < 10 to be <= 10 as in your description.

Mike
Reply With Quote
  #3 (permalink)  
Old 12-27-09, 16:12
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
Count()

Tanks Mike, it works great. I went for a long walk and realized I need to use have or max. Anything that looks simple isn't!

nick
Reply With Quote
  #4 (permalink)  
Old 12-30-09, 08:43
bklr bklr is offline
Registered User
 
Join Date: Dec 2008
Posts: 133
r u can use derived query
but prefer mike_bike_kite query than this one............

select * from (SELECT pre_28_reg, count(*) AS count
FROM Meet_reg
WHERE pre_28_reg =2
GROUP BY pre_28_reg)s where count < 10
Reply With Quote
  #5 (permalink)  
Old 12-30-09, 09:40
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
COunt()

Interesting, so the alias for the derived doesn't need an AS?..thanks!

Nick
Reply With Quote
  #6 (permalink)  
Old 12-30-09, 10:02
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
best practice is always to code AS, even though it is optional

(oracle developers will argue the opposite, since oracle, for some inexplicable reason, doesn't support AS)

here's a good example...

how many columns does this query return?
Code:
SELECT frabilgimjer,
       quistipunctous,
       scrimflabat
       horbliston,
       haplistplogget,
       opsilfrummer,
       whipfintaggle
  FROM ...
coding style matters!!!

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On