S
S
SurelL2019-07-15 13:19:26
Oracle
SurelL, 2019-07-15 13:19:26

How to add custom column to SQL output?

There is a request:

select count(d.id) as КОЛИЧЕСТВО from deal d
where d.status in ('3', '4')

It turns out a table:
QUANTITY
32
12
And it is necessary that it be, if status 3, then an error, and if 4, then success:
QUANTITY STATUS
32 ERROR
12 SUCCESSFUL

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Skibin, 2019-07-15
@SurelL

SELECT COUNT(d.id) AS КОЛИЧЕСТВО, (CASE WHEN d.status = '3' THEN 'ОШИБКА' ELSE 'УСПЕШНО' END) AS СТАТУС
FROM deal d
WHERE d.status IN ('3', '4')
GROUP BY d.status

A
Anton, 2019-07-31
@Oraclist

SELECT COUNT(d.id) AS КОЛИЧЕСТВО, CASE WHEN d.status = '3' THEN 'ОШИБКА' ELSE 'УСПЕШНО' END AS СТАТУС
FROM deal d
WHERE d.status IN ('3', '4')
GROUP BY CASE WHEN d.status = '3' THEN 'ОШИБКА' ELSE 'УСПЕШНО' END

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question