I have created a table containing book details as follows
Now I want to perform operation on the above table such that I should receive result as below
where Qty in above table is total number Of (Book Sl No) for which all the the fields (Book Manufacturer, Book Model,Vendor, Dispatch Date and Lot) are same
I have tried simple "pivot" and "group by" in Sql Server but the above one is a bit complex for me. So could anyone please help me out with this?
Thanks in advance
Select BookManufacturer , BookModel , Vendor , DispatchDate , Lot , Count(*) as Qty
from Books
group by (BookManufacturer , BookModel , Vendor , DispatchDate , Lot)
Looks like you don't need Pivot or any complex query
. A simple Group by
with count
should do the job
SELECT [book manufacturer],
[Book Model],
Vendor,
[Dispatch Date],
lot,
Count(1) Qty
FROM tablename
where [Dispatch date] >= 16/4/2014
GROUP BY [book manufacturer],
[Book Model],
Vendor,
[Dispatch Date],
lot
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.