Unfortunately I have a poorly designed table that I need to query. The sample data and desired query result are listed below.
I need to write a query that will result in the first column name that's found where the value is less than 20,000 (for example) for that item. If it's not possible to return the name of the column, a count of the columns found that are less than 20,000 would also work. I've been able to do this in Excel by using the "MATCH" and "COUNTIF" functions combined, but I'm struggling with how to do this in SQL. Thanks for any help.
Table1
Item,Day0,Day1,Day2,Day3,Day4,Day5
"ABC1","8,192","15,328","22,528","29,536","36,672","36,672"
"ABC2","500","1,328","15,000","19,536","26,672","36,672"
"ABC3","192","328","18,000","29,536","36,672","36,672"
Desired Result
Item,Column
"ABC1","Day1"
"ABC2","Day3"
"ABC3","Day2
I need to write a query that will result in the first column name that's found where the value is less than 20,000 (for example) for that item. If it's not possible to return the name of the column, a count of the columns found that are less than 20,000 would also work. I've been able to do this in Excel by using the "MATCH" and "COUNTIF" functions combined, but I'm struggling with how to do this in SQL. Thanks for any help.
Table1
Item,Day0,Day1,Day2,Day3,Day4,Day5
"ABC1","8,192","15,328","22,528","29,536","36,672","36,672"
"ABC2","500","1,328","15,000","19,536","26,672","36,672"
"ABC3","192","328","18,000","29,536","36,672","36,672"
Desired Result
Item,Column
"ABC1","Day1"
"ABC2","Day3"
"ABC3","Day2