M
M
Mikhail Andronov2019-08-16 00:23:43
SQL
Mikhail Andronov, 2019-08-16 00:23:43

Sql query to calculate sum of rows by 2 columns?

Greetings!
There is a table with 2 columns, 1 column Port 2 Subscriber
There are empty lines in the second column.
It is required by one SQL query to calculate the sum of rows in column 1 and the sum of rows in column 2, excluding empty rows.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitsliputsli, 2019-08-16
@Vitsliputsli

select
 count(port) ports_count,
 count(case when abonent!='' then 1 else null end) abonents_count
from ports

Counts the number of port and abonent strings, excluding null and an empty string for abonent. If null and empty string are the same, then no case is needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question