I'm trying to query how many times each record exists on a column in my table from database in WordPress and export that column. How would I do this?
In the excel exported I want to have the column from meta_value with meta_key "user_valid" and a column with the count of how many times that meta_value exists in the mysql column.
meta_key meta_value
user_valid '1, 2, 3'
user_valid '1, 2, 1'
user_valid '1, 2, 3'
For exporting the column 'meta_value' with the meta_key 'user_valid' I used:
SELECT meta_value FROM `us_test` WHERE meta_key = 'user_valid'
And I export with the export button from MYSQL after using this query.
I don't know how to do the query for the other column.
I think it should be something like this but I'm not sure, because when I use the next query it doesn't return all the records:
SELECT meta_value, COUNT( * ) c FROM `us_test` WHERE meta_key = 'user_valid' GROUP BY meta_value
So, I will answer my own question:
The query from my question is absolutely correct:
SELECT meta_value, COUNT( * ) c FROM `us_test` WHERE meta_key = 'user_valid' GROUP BY meta_value
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments