Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 7,2000
»
SQL Server Newbies
»
Group by select problem
Group by select problem
Rate Topic
Display Mode
Topic Options
Author
Message
bsasiju
bsasiju
Posted Monday, October 15, 2007 7:39 AM
Forum Newbie
Group: General Forum Members
Last Login: Thursday, July 8, 2010 9:10 AM
Points: 5,
Visits: 69
Hi all
have developed my library project counter problem when I want to get sum
book status (in , out ,lost,damage and removed) of the same title from master Book table vs details Book table in one row.Master book table link with detail table field bookID and their status field on the book details have 1=in,2=out,3=lost,4=damage,5=removed .I tried to use group by method but got sum their status of same title different rows
Please need you help
thank in advanced
Post #410817
ALZDBA
ALZDBA
Posted Monday, October 15, 2007 7:49 AM
SSCertifiable
Group: General Forum Members
Last Login: Thursday, March 5, 2015 11:58 PM
Points: 6,783,
Visits: 8,661
Maybe this gets you started...
Select M.BookId, D.[status], count(*) as NumberOfOccurrences
from [master Book table] M
inner join [details Book table] D
on M.bookID = D.BookId
Group by M.BookId, D.Status
Johan
Don't drive faster than your guardian angel can fly ...
but keeping both feet on the ground won't get you anywhere
-
How to post Performance Problems
-
How to post data/code to get the best help
-
How to prevent a sore throat after hours of presenting ppt ?
"press F1 for solution", "press
shift
+F1 for urgent solution"
Need a bit of Powershell? How about
this
Who am I ?
Sometimes this is me
but
most of the time this is me
Post #410820
bsasiju
bsasiju
Posted Monday, October 15, 2007 8:07 AM
Forum Newbie
Group: General Forum Members
Last Login: Thursday, July 8, 2010 9:10 AM
Points: 5,
Visits: 69
thank for you answer
but I hope you
did not get me well I want to get sum of status Book i.e In book,out Book Lost book,Damage and Removed as table fields for each title book
thanks in advance
Post #410843
Matt Miller (#4)
Matt Miller (#4)
Posted Monday, October 15, 2007 9:03 AM
SSCertifiable
Group: General Forum Members
Last Login: Today @ 7:34 AM
Points: 7,239,
Visits: 16,021
Sounds like you might be looking for a "pivot query" solution. Something like:
Select M.BookId, M.booktitle,
sum(case when d.status=1 then 1 else 0 end) as TotalIn,
sum(case when d.status=2 then 1 else 0 end) as TotalOut,
sum(case when d.status=3 then 1 else 0 end) as TotalLost,
sum(case when d.status=4 then 1 else 0 end) as TotalDamaged,
sum(case when d.status=5 then 1 else 0 end) as TotalRemoved
from [master Book table] M
inner join [details Book table] D
on M.bookID = D.BookId
Group by M.BookId, M.booktitle
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Post #410874
bsasiju
bsasiju
Posted Tuesday, October 16, 2007 12:06 AM
Forum Newbie
Group: General Forum Members
Last Login: Thursday, July 8, 2010 9:10 AM
Points: 5,
Visits: 69
thanks a lot its work
Post #411127
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2015 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.