Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Help with a whereclause that filter out values so max changes

$
0
0

I don't really need specific sql, but I just need a general direction for how to proceede.

To simplify the problem then I have a table with 3 fields: BaseId, Id and StatusId.

The same baseId will have several Id and StatusId, Sampledata could look like this

BaseId : 1, Id : 1, StatusId: 21

BaseId : 1, Id : 2, StatusId: 22

BaseId : 1, Id : 3, StatusId: 23

BaseId : 2, Id : 4, StatusId: 21

BaseId : 2, Id : 5, StatusId: 22

I always want the Id with the Highest StatusId, e.g. Id 3 + 5, but I also want to filter so if I only want status 23 then I get Id 3, and if I only want status 22 then I get Id 2 + 4. StatusId 22+23 should then give Id 3+5

My hope is to make a view I can then use in some easy way.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>