sql >> Base de Datos >  >> RDS >> Sqlserver

SQL obtiene el valor más alto y 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