Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


PHP Mysql Syntax For Count and Select

Posted on 2011-03-21
Medium Priority
Last Modified: 2012-06-21

 I want to count and select multiple items in a table.

 I want to select members who opened more than 15 threads in the last 15 days.

 Threadid - userid - dateline are the column names.

How can i select and list these userids?
Question by:mescalin
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

ID: 35183819
This will do:

SELECT *, COUNT(*) as num_threads FROM `table` WHERE  DATE_SUB(CURDATE(),INTERVAL 15 DAY) <= dateline  GROUP BY `userid` HAVING num_threads > 15 ORDER BY aantal DESC

Open in new window

I'm not sure what kind of value you have in dateline but let me know if this doens't work so you can give me some more detail on that field.

Accepted Solution

Rik-Legger earned 2000 total points
ID: 35183822
Correction in query:

SELECT *, COUNT(*) as num_threads FROM `table` WHERE  DATE_SUB(CURDATE(),INTERVAL 15 DAY) <= dateline  GROUP BY `userid` HAVING num_threads > 15 ORDER BY num_threads DESC

Open in new window


Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA:…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question