July 27, 2008 at 8:12 pm
Hello friends
I have a tabe of LabTests and I need to add two new columns to this table with two different conditions.
Here is the sample data
Lab TestName TotalTests Tests 2
Alcohol 12 ? ?
VVV 2 ? ?
QQQQ 123 ? ?
Now I need to calculate two columns
1. Tests <= 2 which means those tests which are less than or equal to a total of 2
2. Tests > 2
How do I do it in a single query.
I know I can calculate in two queries and then join them
Any thoughts??
Thanks
July 27, 2008 at 8:26 pm
First you need to provide more data that would show how you get the test2 data as well as the results you are looking for.
Second, this seems like homework or a test question. Please make an attempt to write a query.
July 28, 2008 at 9:52 am
Will this work?
CASE WHEN TotalTests >2 THEN '3PLUS' ELSE '2MINUS' END AS Tests2
Or do you need two additional columns:
CASE WHEN TotalTests <= 2 THEN 1 ELSE 0 END AS TEST2,
CASE WHEN TotalTests > 2 THEN 1 ELSE 0 END AS TEST3
July 29, 2008 at 9:32 pm
Works Well
Thnks
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply