Sqlserver
 sql >> Base de Dados >  >> RDS >> Sqlserver

SQL obtém o valor mais alto e concatena

select  ProductID
        ,StockOnSite
        ,StockOffsite
        ,StockOnSite - StockOffsite
        ,cast(Stockonsite as varchar(10))+'/' +cast(StockOffsite as varchar(10)) 
from    Products pr1
where   StockOnSite - StockOffsite = (Select max(StockOnSite - StockOffsite)
                                        from Products pr2
                                        where   pr1.ProductID = pr2.ProductID
                                        )
group by ProductID, StockOnSite, StockOffsite