home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.ms-sqlserver      Notorious Rube Goldberg contraption      19,505 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 17,795 of 19,505   
   Benjamin Kalytta to All   
   Re: Keeping rows with the minimum differ   
   30 Apr 10 18:00:44   
   
   From: bkausbk@web.de   
      
   Hello Mr. Ratchev,   
      
   > Here is a query that works in SQL CE:   
   > [...]   
      
   Thank you for that, it really works. I even understand your query, don't   
   know why I wasn't able to find it by my self.   
      
   However my real query will be a bit more complex because there is not   
   only one metric to compare, but several metrics. This compareable   
   metrics are stored in another table which will be referenced by their   
   MAC Address:   
      
   JOIN DeviceTable C ON (C.Id = A.DeviceId AND (C.MacAddress =   
   0x1234567890ab OR C.MacAddress = ... OR ...)) ...   
      
   I don't know if it is better to use UNIONS here or to make your query a   
   bit more complex if that even works:   
      
   SELECT A.RouterId, A.DeviceId, A.Metric   
   FROM LinkTable AS A   
   JOIN DeviceTable AS C ON (C.Id = A.DeviceId AND (C.MacAddress =   
   0x1234567890ab OR C.MacAddress = ... OR ...))   
   JOIN (SELECT RouterId, DeviceId, MIN(ABS(C.Metric - Metric)) AS min_metric   
          FROM LinkTable   
          GROUP BY RouterId, DeviceId) AS B   
   ON B.DeviceId = A.DeviceId   
   AND B.RouterId = A.RouterId   
   AND ABS(C.Metric - A.Metric) = min_metric;   
      
   But that should work isn't it?   
      
   Regards,   
   Benjamin Kalytta   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca