R
R
rd1002021-09-22 01:37:49
MySQL
rd100, 2021-09-22 01:37:49

How to get unique column values ​​and their number?

SELECT DISTINCT brand, age FROM productswith such a record, it gives me an object with 2 keys for brand and age, but I need their unique names in the trailer, and not uniquely grouped in pairs, because there is the uniqueness of the varieties of keys in 2 fields, which are often repeated in terms of brand names and age.
I also need their number.
SELECT DISTINCT brand, COUNT(brand) FROM products
With such a record, for some reason it displays {"brand":"Heinz","COUNT(brand)":162}

How do I get the unique field values ​​​​and their number?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-09-22
@rd100

SELECT `brand`, COUNT(*) AS `count`
  FROM `products`
  GROUP BY `brand`

And a similar query with age.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question