Extracting row from a group, basing on a condition
===

    CREATE TABLE [Items]
    (
      [ItemId] INT NOT NULL,
      [CategoryId] INT NOT NULL,
      [ItemValue] [int] NOT NULL
    )

A table contains items. Every item belongs to a category and stores some numeric value.

As a result of a query, I want each row to represent a category. There should be three columns:

- category id;
- id of an item with the highest `ItemValue` per category;
- id of an item with the lowest `ItemValue` per category.

Performance of the query is important. I use MS SQL Server.