I'm investigating how to easily figure out the number of duplicates in php and mysql.
If i have such a database, how do you count the number of apples, grapes, cucumbers and pears?
If the number is small
$count = 'SELECT COUNT (*) FROM db_name WHERE name = "apple"'; $count = $pdo->prepare ($count); $count->execute (); $apple_count = $count->fetchColumn ();
I thought it would be good to ask in this way, but I don't know how to solve it when there are nearly 20 products.
Answer # 1
You can get the number of each by executing
SELECT count (id) as cnt, name FROM table GROUP BY name
Answer # 2
The grapes and pears do not overlap, but is it better to display them with a quantity of 1?
SELECT name, count (*) as cnt FROM table GROUP BY name HAVING count (*)>1
- php - i want to get the number of arrays in the repeating field of advanced custom fields
- cannot register to mysql in php input form
- [php] the reason why the query to mysql fails
- i want to get the number of partitions by specifying conditions in mysql
- php - the bug that the dakuten in mysql is not treated as one character
- i want to prevent the serial number of ids from being broken by deleting the [cakephp] table [db]
- php - xampp mysql does not start
- sql: joining tables that count the number of items
- php - localhost name does not change when connecting mysql database
- i want to display each number with $_get on the date of the calendar made with php and pass it to the transition page by clickin
- php - what should the minimum number of records for creating a master table be?
- i want to get the elements below a specific number in the php array
- display values with low occurrence count in php array
- how to set product ranking using php and mysql
- php - i want to connect to mysql! !!
- php - insert if there are no duplicate rows for all record fields if all rows are duplicated, increment the count and update
- php - i want to display some number in the list
- delete message with matching number and password from mysql using pdo in php
- php - i want to delete unnecessary characters in the phone number retrieved from the database using the hp method
- php - can't update variable to mysql
- i'm not sure if the third argument of php's bindvalue is typed reliably
- i can't do php $stmt-> execute ()
- php - how to access the database in the server on www with pdo from the local development environment
- use php pdo::fetch_assoc
- how to write code when connecting to mysql with pdo in php and executing multiple sqls
- about code for creating tables using mysql and php
- php - join and display tables in sql
- php - tables cannot be linked by belongstomany in laravel
- php - about running programs on vps
- php - format date with datetime() and output to html