0

I want to create a new table from an existing table that has numeric values. I want to be able to classify my data into two groups based on how high the number is. If the number is over 20 then it needs to go into group 'High", if it's below that then group 'Low'.

My existing table looks something like this

task A Days in progress
Task 1 22
Task 2 31
Task 3 55
Task 4. 100

I know this is probably a case when mixed with something else, but I'm not sure where the existing table information needs to be called, and how I can just get the values that I'm now trying to count into a new column.

I saw this earlier and tried working with it:

SELECT 
    COUNT(CASE WHEN rsp_ind = 0 then 1 ELSE NULL END) as "New",
    COUNT(CASE WHEN rsp_ind = 1 then 1 ELSE NULL END) as "Accepted"
from tb_a

I initially started here with an example:

SELECT COUNT (T1.'days in progress') AS '<=7'
FROM T1
WHERE 'days in progress'<=7
;

using sql count in a case statement

I tired building my own SQL query.

David784
  • 7,031
  • 2
  • 22
  • 29
Ndaudio
  • 11
  • 1

1 Answers1

3

You just need a case expression.

Sample table:

SQL> select * from test;

TASK_A       DAYS
------ ----------
task 1         22
task 2         31
task 3         55
task 4        100
task 5          7

Query:

SQL> select task_a, days,
  2    case when days > 20 then 'High'
  3         else 'Low'
  4    end as status
  5  from test;

TASK_A       DAYS STATUS
------ ---------- -------
task 1         22 High
task 2         31 High
task 3         55 High
task 4        100 High
task 5          7 Low

SQL>
Littlefoot
  • 131,892
  • 15
  • 35
  • 57