oracle - Counting how many data that exist [SQL] -


im not sure question asked else or not yet because easy head still can't see way out of problem.

how many times sampling @ material.

select   table01.material_no,   table01.sample_tempt1,   table01.sample_tempt2,   table01.sample_tempt3,   table01.sample_tempt4,   table01.sample_tempt5   table01 

is possible create column show count of sample_tempt times?
mean, if tempt1 tempt2 data exist, column shows 2, when tempt2, tempt4 , tempt5 data exist, column show 3. , on.
thank helping me ^^
sample :

material no | sample_tempt1 | sample_tempt2 | sample_tempt3 | sample_tempt4 | sample_tempt5 |  po1025           120            150                               102                         po1026                          122 

for po1025, want create new column generate "3" because sample data exist 3, po1026 want generate "1" since sample data exist "1". quite simple right?

if "by exist" mean "value not null", can count number of non-null values in each row as:

select t1.material_no,        t1.sample_tempt1, t1.sample_tempt2, t1.sample_tempt3, t1.sample_tempt4, t1.sample_tempt5,        ((case when t1.sample_temp1 not null 1 else 0 end) +         (case when t1.sample_temp2 not null 1 else 0 end) +         (case when t1.sample_temp3 not null 1 else 0 end) +         (case when t1.sample_temp4 not null 1 else 0 end) +         (case when t1.sample_temp5 not null 1 else 0 end)        ) numtempts table01 t1; 

note introduced table alias. makes query easier write , read.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -