A
A
A1K02021-01-30 21:05:17
SQL
A1K0, 2021-01-30 21:05:17

Need help with a CASE query?

Hello, guys, who will tell you how to write such a request that considered the conversion,
for example, there is a field ID, STATUS
STATUS has the following values ​​1,2,3,4,5
1 - this is a successful status
!= 1 all unsuccessful
, here's how I can calculate the conversion using CASE help plz because i ended up with this

SELECT
COUNT(*)FILTER(WHERE STATUS = 1) SUCCESS,
COUNT(*)FILTER(WHERE STATUS != 1) UNSUCCESS,
FROM TABLE

The arithmetic is:
success / (success+fail) * 100

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2021-01-30
@A1K0

Subquery?

SELECT SUCCESS * 100 / (SUCCESS + UNSUCCESS) FROM (
  SELECT
  COUNT(*)FILTER(WHERE STATUS = 1) SUCCESS,
  COUNT(*)FILTER(WHERE STATUS != 1) UNSUCCESS,
  FROM TABLE
) AS T

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question