MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 6th, 2012, 05:59 PM
karnival800 karnival800 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 35 karnival800 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 15 m 8 sec
Reputation Power: 1
Using a 'COUNT as' in a 'WHERE'

Getting an error when trying to return a where from count as daily count....please help
Code:
   
SELECT customers.lead_type
, ac0
, ac1
, ac2
, ac3
, ac4
, active
, daily 
, timezone
, run
, pri
, customers.id
, customers.carrier
, customers.state
,customers.customer
, MAX(xferleads.timestamp)AS maxTimeStamp
,COUNT( CASE WHEN xferleads.timestamp >= CURRENT_DATE 
                    AND xferleads.timestamp  < CURRENT_DATE + INTERVAL 1 DAY 
                   AND woactive>0
                   THEN xferleads.customer
                   ELSE NULL END ) AS countdaily

FROM customers 
LEFT JOIN xferleads ON xferleads.customer = customers.id
LEFT JOIN fulfillment ON fulfillment.id = customers.id



WHERE 
     (customers.lead_type='PRE' OR customers.lead_type = 'ANY') 
     AND (ac0 =818 OR ac1 = 818 OR ac2 = 818 OR ac3 = 818 OR ac4 = 818) 
     AND active=1 AND countdaily < (daily * 1.5) 
     AND Tue = 1 

GROUP BY customers.customer

Reply With Quote
  #2  
Old November 6th, 2012, 06:29 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,375 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 7 h 30 m 16 sec
Reputation Power: 4140
change this --
Code:
WHERE 
     (customers.lead_type='PRE' OR customers.lead_type = 'ANY') 
     AND (ac0 =818 OR ac1 = 818 OR ac2 = 818 OR ac3 = 818 OR ac4 = 818) 
     AND active=1 AND countdaily < (daily * 1.5) 
     AND Tue = 1 
GROUP BY customers.customer

to this --
Code:
 WHERE customers.lead_type IN ('PRE','ANY') 
   AND 818 IN (ac0,ac1,ac2,ac3,ac4) 
   AND active = 1 
   AND Tue = 1 
GROUP 
    BY customers.customer
     , daily
HAVING countdaily < (daily * 1.5)
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Using a 'COUNT as' in a 'WHERE'

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap