A little explanation of this mysql code

I received this answer from someone else Q before, but I would like to get an explanation of this so that I fully understand the problem.

I have a table with a column that contains the value of either "private" or "company". The thing is, I want to check how many "private" and "company" values ​​are in my records, so that I can display them with the search results later. So if there are 4 company ads and 1 private ad, this is the result:

  Company = 4
  Private = 1
  All ads = 5

And here is the code I received from someone about how to do this, in other words, this is what I would like to explain:

SELECT
    IFNULL( field , 'All ads' ) AS 'Type',
    COUNT( * )
FROM
    `table`
GROUP BY
    field
WITH ROLLUP

thank

+1
source share
3 answers

Type, null, All Ads .

table .

, "", , , " ".


BTW, IFNULL(), . IF NULL, , - NULL. . , , . , , , , null.

0

, , , ROLLUP, .

, , , , Field NULL.

IFNULL NULL . COALESCE IFNULL, .

+4

"table", , , , "", "public" . , 10 , " " 10.

It makes sense?

0
source

Source: https://habr.com/ru/post/1731768/


All Articles