Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

SQL ottiene il valore più 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