How to count how many times a meta_value appears in a column by certain meta_key?

Ionut Necula

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
Ionut Necula

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.

edited at
0

Comments

0 comments
Login to comment

Related

Count how many times a value appears and adding the result to a column

Count How Many Times a Value Appears Php

SQL COUNT how many times a value appears

Count how many times a value appears in this array?

Count how many number of times a value appears

Count how many times a column contains a certain value in Pandas

Recursion function to count how many times a certain sequence appears

Look for a certain String inside another and count how many times it appears

EXCEL: I want to count how many times a certain word appears in a column if it's in the same row if another word appears

How to select all meta values of certain meta_key's?

Count how many times a field attribute appears in a column

Is there a excel formula to count how many times an ID appears in a column when the value in another column is YES?

MySQL: Count how many times value in one column appears in another column

Play Framework: Count how many times a key exists in a JSON tree and how many times is set to a certain value

How can I get a count of how many times a distinct value appears in a column?

How do I count how many times a value appears in a MySQL column?

Count how many times a particular value appears with respect to value in another column

Update table wp_postmeta column meta_value where meta_key column equals certain value

How to copy meta_value of wp_usermeta to the same table however different meta_key?

Excel: How to count how many times a consecutive text value appears

Count how many times a value appears continuously in Hive/SQL

Count how many times a value appears in tables SQL

Count how many times a value appears per month in dataframe

Excel - how to count how many times a word appears within a certain date range

needs to find how many times each number in a column appears and adding a column to show the count

Count how many times a certain value per user has changed

How do I create a column that tells me the the count of how many times a number appears?

Count how many string value appears in a column R Programming

Count how many repeated times each record appears and select minimum and maximum of specific column

TOP Ranking

HotTag

Archive