0
  1. I have created a table in Data Extension that contains 4 fields. All fields are Nullable. One field Name is Checked. In that field the values are Yes and No according to the requirement. Now I want Max count of either YES or NO and that need to be saved in another table in a new column.

  2. Can anyone help me in building this query.

Currently using:

Select Check, CASE
                  COUNT(distinct Winner)
                  WHEN Yes THEN 'Yes'
                  ELSE 'No'
              END as winner
FROM Test_Table

I changed my Query this way:

select max(Final) as Winner from (
                Select distinct Seafood, max(Seafood) as Final
                 from Tirumala_Testing_New
                  group by Seafood
                         ) A

This is not printing the max value it is just taking the random value how to display max value

6
  • Select Check, case count(distinct Winner) when Yes then 'Yes' else 'No' end as winner from Test_Table(I tried this) But it is not working Commented Oct 27, 2017 at 16:44
  • 1
    Please be more specific than it is not working.
    – Adrian Larson
    Commented Oct 27, 2017 at 16:56
  • Am getting syntax error near the variable name Check Commented Oct 27, 2017 at 16:58
  • You aren't using the case function properly
    – 0xsegfault
    Commented Oct 27, 2017 at 17:15
  • Count distinct winner is an agregate function and cannot return a string "yes"
    – 0xsegfault
    Commented Oct 27, 2017 at 17:18

1 Answer 1

0

Try this:

SELECT 


Max(Winner) as Winner


FROM 

(CASE WHEN Checked IS NOT NULL THEN 1 END as Winner FROM Tirumala_Testing_New UNION
CASE WHEN Column1 IS NOT NULL THEN 1 END as Winner FROM Tirumala_Testing_New UNION
CASE WHEN Column2 IS NOT NULL THEN 1 END as Winner FROM Tirumala_Testing_New UNION
CASE WHEN Column3 IS NOT NULL THEN 1 END as Winner FROM Tirumala_Testing_New) x

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .