Pergunta

My image, explanation

  • I need to count the foreign key that does not exist, as shown in Fig. And containing the letter 'a' in the name of the list.
  • I can only count values​​, but no way to specify the names with the letter 'a'.

I'm using for count:

SELECT l.identifier AS id, l.name AS listName, COUNT(p.list_identifier)
AS regCount FROM list AS l LEFT JOIN person AS p ON l.identifier = p.list_identifier
WHERE p.list_identifier IS NULL GROUP BY l.name;

Help me, please.

Foi útil?

Solução

Try using a left outer join & COUNT(DISTINCT ...)

SELECT COUNT(DISTINCT l.identifier) AS regCount
FROM list AS l LEFT OUTER JOIN person AS p ON l.identifier = p.list_identifier
WHERE l.Name LIKE '%a%'
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top