how do i get the sum of this?

here's my query

SELECT DISTINCT tbl_filedetails.vfilepathclient, tbl_filedetails.iactualsize
FROM         tbl_filedetails INNER JOIN
                      tbl_userdetails ON tbl_filedetails.vuserid = tbl_userdetails.vuserid
WHERE     (tbl_userdetails.vuname = 'april10test') AND (NOT (tbl_filedetails.vbkpk IN
                          (SELECT     vbkpk
                            FROM          tbl_deletedfiledetails
                            WHERE      vuserid = tbl_userdetails.vuserid)))

How do i modify this so i get the sum of all the iactualsize records this returns?
LVL 4
kenshawAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Patrick MatthewsCommented:
Hi kenshaw,

SELECT tbl_filedetails.vfilepathclient, SUM(tbl_filedetails.iactualsize) AS SumOfSize
FROM         tbl_filedetails INNER JOIN
                      tbl_userdetails ON tbl_filedetails.vuserid = tbl_userdetails.vuserid
WHERE     (tbl_userdetails.vuname = 'april10test') AND (NOT (tbl_filedetails.vbkpk IN
                          (SELECT     vbkpk
                            FROM          tbl_deletedfiledetails
                            WHERE      vuserid = tbl_userdetails.vuserid)))
GROUP BY tbl_filedetails.vfilepathclient

Regards,

Patrick
imran_fastCommented:
SELECT  tbl_filedetails.vfilepathclient, sum(distinct tbl_filedetails.iactualsize)
FROM         tbl_filedetails INNER JOIN
                      tbl_userdetails ON tbl_filedetails.vuserid = tbl_userdetails.vuserid
WHERE     (tbl_userdetails.vuname = 'april10test') AND (NOT (tbl_filedetails.vbkpk IN
                          (SELECT     vbkpk
                            FROM          tbl_deletedfiledetails
                            WHERE      vuserid = tbl_userdetails.vuserid)))
group by tbl_filedetails.vfilepathclient
LowfatspreadCommented:
if you have multiple filedetails for a user in a filepath....
how do you want the filedetails to be selected ?

do you have the last accessed date or something similar?

e.g.

select f.vfilepathclient,sum(f.iactualsize)
  from tbl_fieldetails as f
 inner join tbluserdetails as u
     on u.vuserid=f.vuserid
 where u.vuname='april10test'
     and not exists (select vbkpk
                              from tbl_deletedfiledetails as x
                             where x.vuserid=u.vuserid)
    and f.dateaccessed = (select max(y.dateaccessed)
                                        from tbl_fieldetails as y
                                       where y.vfilepathclient=f.vfilepathclient
                                           and y.vuserrid=u.vuserid
                                    )

note exists syntax can perform better than in syntax


hth  
dqmqCommented:
This gives the sum along with the detail, but in a separate column:


SELECT DISTINCT tbl_filedetails.vfilepathclient, tbl_filedetails.iactualsize,  sum.iactualsizesum as total
FROM         tbl_filedetails
 INNER JOIN   tbl_userdetails ON tbl_filedetails.vuserid = tbl_userdetails.vuserid
 INNER JOIN                      
(
SELECT dis.vfilepathclient, sum(dis.iactualsize) as iactualsizesum
(
SELECT  distinct f.vfilepathclient, f.iactualsize
FROM         tbl_filedetails as f INNER JOIN
                      tbl_userdetails as u ON f.vuserid = u.vuserid
WHERE     (u.vuname = 'april10test') AND (NOT (f.vbkpk IN
                          (SELECT     d.vbkpk
                            FROM          tbl_deletedfiledetails as d
                            WHERE      d.vuserid = u.vuserid)))
group by f.vfilepathclient
) as dis
) as sum
WHERE     (tbl_userdetails.vuname = 'april10test') AND (NOT (tbl_filedetails.vbkpk IN
                          (SELECT     vbkpk
                            FROM          tbl_deletedfiledetails
                            WHERE      vuserid = tbl_userdetails.vuserid)))

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.