All Forums Analytics
AndrewLivingston 36 posts Joined 07/07
10 Sep 2008
Hiding a column from output

Hello!

Consider the following SQL:

SELECT CUST_ID
,DTE_BIRTH
,(DATE-DTE_BIRTH)/365.25 As AGE
,CASE
WHEN AGE < 18
THEN 'Under 18'
WHEN AGE BETWEEN 18 and 65
THEN 'Between 18 and 65'
WHEN AGE > 65
THEN 'Over 65'
Else 'Missing Data'
End
From TABLE;

I've used the 3rd column only to be able to refer to it then in the CASE statement.

Is there anyway to suppress this column from the answerset?

Thanks!

Andrew

Jim Chapman 260 posts Joined 09/04
10 Sep 2008

Define a WITH query, derived table, or view containing the AGE derived column. You can then reference it in the case expression without including it in the select list of the main select.

Adeel.Chaudhry 272 posts Joined 04/08
10 Sep 2008

Hello,

You can also try following:

SELECT CUST_ID
,DTE_BIRTH
,CASE
WHEN (DATE-DTE_BIRTH)/365.25 < 18
THEN 'Under 18'
WHEN (DATE-DTE_BIRTH)/365.25 BETWEEN 18 and 65
THEN 'Between 18 and 65'
WHEN (DATE-DTE_BIRTH)/365.25 > 65
THEN 'Over 65'
Else 'Missing Data'
End
From TABLE;

As far as performance (re-calculating same value on each WHEN) is concerned, atleast the explain is pretty identical in both cases. Though you should try it running on actual data.

HTH.

Regards,

Adeel

Fred 415 posts Joined 08/04
10 Sep 2008

Or if you don't mind using old-style Teradata extensions:

SELECT CUST_ID
,DTE_BIRTH
,CASE
WHEN (DATE-DTE_BIRTH)/365.25 (named AGE) < 18
THEN 'Under 18'
WHEN AGE BETWEEN 18 AND 65
THEN 'Between 18 and 65'
WHEN AGE > 65
THEN 'Over 65'
ELSE 'Missing Data'
END
FROM TABLE;

AndrewLivingston 36 posts Joined 07/07
26 Sep 2008

Thanks everyone!

Adeel, thanks for your suggestion, I was trying to get around that so I could use Age instead of the formula.

Fred, I might just use the old Teradata extension in that way. Personally I think showing the actual age column is good so that you can prove the data.

Thanks for your suggestions!

You must sign in to leave a comment.