Reputation: 957
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
Upvotes: 2
Views: 4441
Reputation: 311163
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
Upvotes: 4
Reputation: 4630
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
Upvotes: 1
Reputation: 1087
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
Upvotes: 1