I have a column in my table users
that's called user_model
. It contains different reoccurring names as, value1
value2
value3
etc.
I want to count how many times all the different names occur and sort them by largest to smallest value.
How can I do that?
SELECT user_model, COUNT(*) totalCOUNT
FROM users
GROUP BY user_Model
ORDER BY totalCOunt DESC
<?php
$link = mysql_connect('localhost', 'root', '123456');
if (!$link) {
die('Not connected : ' . mysql_error());
}
// make foo the current db
$db_selected = mysql_select_db('testing', $link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
$sql = "select count(a.title),a.title from le7im_menu a, le7im_menu b WHERE a.title = b.title GROUP BY a.title";
$res=mysql_query($sql);
while ($row=mysql_fetch_array($res)){
$rows[]= $row;
}
print_r($rows);
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.