Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Calculate User Payment

$
0
0
Hi DearsI Have This Structure :[code="other"]--ActionType=1 UserPay--ActionType=2 UserBackCreate Table P(Id int , Pay int,Userid int,ActionType smallInt)Insert Into P Values(1,1000,300,1),(2,2500,300,1),(3,500,300,2) ,(4,750,301,1),(5,200,301,1),(6,3000,302,1),(6,3000,302,2)Select * from PCreate Table PO(PId int, Cartid int)Insert Into PO Values(1,44),(2,44),(3,44),(4,55),(5,55),(6,66),(7,66)Select * from POSelect * from P Inner Join Po On P.id=PO.PID-------------------------------------------------------------------------[/code]And I Need This Result. [code="other"]-- I Nead This Result : Row 1 : Userid=300, Cartid=44, pay=3500, Back = 500, Pure = 3000 Row 2 : Userid=301, Cartid=55, pay=950, Back = 0 , Pure = 950 Row 3 : Userid=302, Cartid=66, pay=3000, Back = 3000, Pure = 0[/code]It means I need one record for every : (Userid , Cartid) . MoreOver for every Record sum of pay and sum of back is needed . Please Guide Me . Thank You

Viewing all articles
Browse latest Browse all 3145

Trending Articles