TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Anilananda Chakrabortty
NA
425
78k
Multiple row Subtraction form a single table in SQL
Jun 22 2018 1:08 AM
Hi, can any one help me for this sql table....
i want to wrire a store procedure where i will pass lookupId (FK) based on lookup id it will give the requird output...
here the description....
id
lookupId
size
rate
buySell
1
1
10
10.5
1
2
1
10
10.5
0
3
1
50
11
1
This is my original table .... i have written a quary to get the total based on lookupId and BuySell
(1 = Buy and 0 = Sell)
select lookupId,buySell,
sum(size) as TotalSize ,
sum(size*rate) as TotalPrice
from tblLookupDetails where lookupId=1 group by lookupId,buySell
Its gives me this output >
lookupId
buySell
TotalSize
TotalPrice
1
0
10
105
1
1
60
655
But i want Like this output: form a single Quary (Subtraction should be always 1-0 )
lookupId
Current Size
Total Amount
Avg
1
50
550
11
Thank you in advance...
Reply
Answers (
4
)
Stored procedure
scenario based sql question