Home > Back-end >  Trying to combine 2 columns in sql query
Trying to combine 2 columns in sql query

Time:11-16

SELECT SubscriberKey, COUNT(*) AS TotalSentLast180Days
FROM (
        SELECT s.SubscriberKey
        FROM ENT._Sent s
            INNER JOIN ENT.AllSubscribershistroyland ROCS
                ON ROCS.SubscriberKey = s.SubscriberKey
        WHERE ROCS.SLSegment__c = 'S4 - real-love' 
        AND 'S6 - real-love'
        AND s.OYBAccountID = '85208879'
        AND s.EventDate >= DATEADD(DAY, -180, GETDATE())
    ) t
GROUP BY SubscriberKey

So in the " AllSubscribershistroyland " their are 2 columns that are called 'S4 - Dutch real-love' and 'S6 - real-love'. Im trying to run the query to see how many subscribers are in those 2 columns. I cant seem to combine them but when i run the query for example with one column i do get a result back. I tried the ' AND ' to combine the 2 columns but i get an error code of "

Error saving the Query field. An expression of non-boolean type specified in a context where a condition is expected, near 'AND'.** "

if anyone can help me i would be very grateful

CodePudding user response:

I am not entirely sure what you're trying to do, but if you are just trying to include both of your titles in the where clause for the same column then you could use the IN Clause:

SELECT SubscriberKey, COUNT(*) AS TotalSentLast180Days
FROM (
        SELECT s.SubscriberKey
        FROM ENT._Sent s
            INNER JOIN ENT.AllSubscribershistroyland ROCS
                ON ROCS.SubscriberKey = s.SubscriberKey
        WHERE ROCS.SLSegment__c in ('S4 - real-love', 'S6 - real-love')
        AND s.OYBAccountID = '85208879'
        AND s.EventDate >= DATEADD(DAY, -180, GETDATE())
    ) t
GROUP BY SubscriberKey
  •  Tags:  
  • sql
  • Related