mysql - Determine total amount of top result returned -
mysql - Determine total amount of top result returned -
i determine 2 things single query:
most prevalent column in table the amount of times such column located upon querying tableexample table:
user_id some_field 1 info 2 info 1 infothe above homecoming user_id # 1 beingness prevalent in table, , homecoming (2) total amount of times located in table.
i have done research , came across 2 types of queries.
group user_id order count(*) desc sumthe problem can't figure out how utilize these 2 queries in conjunction 1 another. example, consider next query returns prevalent column.
$top_user = "select user_id table_name grouping user_id order count(*) desc";
the above query returns "1" based on illustration table shown above. now, able homecoming "2" total amount of times user_id (1) found in table.
is chance possible?
thanks,
evan
you can include count(*)
in select list:
select user_id, count(*) totaltimes table_name grouping user_id order count(*) desc;
if want first one:
select user_id, count(*) totaltimes table_name grouping user_id order count(*) desc limit 1;
mysql sql-order-by sum
Comments
Post a Comment