With this DER model I would like to make an sql query that returns me the following information: Type a command that shows how many clients are single.
Let's start by looking at your table diagram.
Given your problem, only two all informed tables are important to get you what you need.
Notice that there is a Cliente
table and a Conjuge
table. Both are related through the column Cod_Cli
, as you can see by the yellow "little key" that connects one to another.
That said, we can understand that only married (or dating) clients will have a spouse, that is, they will have their code referenced in the Conjuge
table.
So we set up an SQL statement that will count how many clients do not have their code referenced in the Conjuge
table, thus identifying single clients:
SELECT COUNT(cliente.Cod_Cli)
FROM Cliente cliente
WHERE cliente.Cod_Cli NOT INT (SELECT conj.Cod_Cli FROM Conjuge conj);