2

Below query I am trying to filter status id =7 records for team_id>1 But want to include records with status_id=7 for team_id=1.How can we write the query.

 SELECT MAX(created_date) AS maxtime,
        TEAM_ID,
        ticket_id 
 FROM ri_ticket_status_history  
 WHERE status_id<>7    
 GROUP BY TEAM_ID,ticket_id
1
  • The description is different from your query. I can not see any team in where statement Commented Mar 11, 2015 at 7:08

3 Answers 3

4

A combination of and and or logical operators should do it:

SELECT   MAX(created_date) AS maxtime ,team_id, ticket_id 
FROM     ri_ticket_status_history 
WHERE    (status_id <> 7 AND team_id > 1) OR team_id = 1
GROUP BY team_id, ticket_id
Sign up to request clarification or add additional context in comments.

2 Comments

It would be better: status_id<>7 AND team_id >= 1
@RenatoReyes - nope, that will exclude rows with status_id=7 and team_id=1.
1

Try

select max(created_date) as maxtime ,TEAM_ID,ticket_id 
from  ri_ticket_status_history 
where status_id<>7  or  (status_id=7 and team_id=1)
group by TEAM_ID,ticket_id

Comments

1

brace location can change the result set.

select max(created_date) as maxtime ,TEAM_ID,ticket_id 
from  ri_ticket_status_history 
where ( status_id<>7  or  (status_id=7 and team_id=1))
group by TEAM_ID,ticket_id

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.