O'Reilly logo

Practical Predictive Analytics by Ralph Winters

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

SQL – computing a new column using the Case statement

The SQL window allows us to utilize all of the benefits of standard SQL. That includes the ability to create new columns. In this example, we query the entire table and compute the average mass split by high mass (>30), and low mass (<-30).

In this way, we can see that the mean mass is higher at the upper end for diabetes patients than for the non-diabetes patients. The same seems to be true at the low end:

%sql select case when mass > 30 then "BMI_HIGH" else "BMI_LOW" end as BMICAT, outcome,avg(mass) from out_tbl group by 1,2  

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required