Hello, the situation is the following, there is a table with id and link columns in the links table, in the id column all cells are numbered (1-30), and in the link not all the cell fields are occupied, the task is to calculate the filled fields.

I tried a bunch of COUNT(*) requests COUNT(*) and others like it, basically, if the script works, it displays the number 1 (and I have 3 records there). I understand that 1 is something like an error signal. Help me please.

Thanks in advance to everyone.

  • SELECT link FROM table WHERE link! = NULL (or default value as an empty string), I don’t know how many rows it will return to calculate, although the method is possible with a relative crutch, I don’t know. - BlackOverlord
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

2 answers 2

The counting strategy for the filled link fields depends on what is in the empty fields. If the empty link fields contain the value NULL, just use the query

 SELECT COUNT(link) FROM links 

The COUNT () aggregate function only counts non-NULL values.

If the empty fields of the link contain an empty string, then you can supplement the query with a WHERE condition that checks whether the value of the link is equal to the empty string.

 SELECT COUNT(link) FROM links WHERE link <> '' 
  • Thank you so much, I was tormented for a long time, I thought what was wrong, but it turns out that's what, empty quotes are needed) - John TRavolta

If the default value for LINK = NULL, then the number of records where this column is filled should return the following query:

 SELECT COUNT(ID) AS count FROM links WHERE link IS NOT NULL; 

If the default value is "", then the request will be as follows:

 SELECT COUNT(ID) AS count FROM links WHERE link <> '';