I'm trying to evaluate 2 rows independently. e.g. check if row1=4 AND
row2 is NOT equal to 2
The query I have is not working. I think its because I'm saying the interface name must be two values at once. Can I do a union here? or does that not apply?
SELECT I.DisplayName, I.Status FROM Interfaces AS I
WHERE ( I.[InterfaceName] = 'GigabitEthernet1/0/2' AND I.[Status] = '4' ) AND ( I.[InterfaceName] = 'GigabitEthernet1/0/1' AND I.[Status] != '2' )
Here is a table sample of these two items.
1条答案
按热度按时间1mrurvl11#
If you're looking into if table has any two rows that both match some condition you can do a following:
The OR matches the conditions you're looking for, the COUNT makes sure you get at least two values.
If you have duplicates and want to make sure you get both interfaces and not just duplicate of one interface, it's a bit more complicated. One solution is:
ROW_NUMBER
creates a grouping of rows per Interface, for which we only take one, and then by wrapping it in anotherCOUNT(*) OVER()
you once again return the two distinct rows