Reputation: 27
i have table like this
I just want to display the data based on the most data appearing in the second field and I do not want to display a little data. So the data appears only the most and count the total value in the third field. And I've tried but no results. How to query the database to display the most data only
Upvotes: 1
Views: 311
Reputation: 279
SELECT
kd_masalah, total_bobot
FROM
(SELECT -- SubQuery
SUM(bobot) AS total_bobot, -- Gives the sum of values in bobot column relating to a particular group (grouped column)
kd_masalah
FROM
your_table_name
GROUP BY kd_masalah -- Grouping of same values in the column
)AS s having MAX(total_bobot); -- return the values having max sum in total_bobot
Upvotes: 0
Reputation: 1610
You can do something like this,
SELECT `col_name_of_frequent_value`,
COUNT(`col_name_of_frequent_value`) AS `frequent_value`
FROM `table_name`
GROUP BY `col_name_of_frequent_value`
ORDER BY `frequent_value` DESC // This will sort the result by putting max count at top.
LIMIT 1; // This will only show the TOP-Most value in sorted result.
Please change the names as per your table structure.
Upvotes: 1