Solved

PHP Mysql Syntax For Count and Select

Posted on 2011-03-21
2
290 Views
Last Modified: 2012-06-21
Hello,

 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?
0
Comment
Question by:mescalin
[X]
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
2 Comments
 
LVL 8

Expert Comment

by:Rik-Legger
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.
0
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 500 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

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

729 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