kenshaw
asked on
how do i get the sum of this?
here's my query
SELECT DISTINCT tbl_filedetails.vfilepathc lient, tbl_filedetails.iactualsiz e
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?
SELECT DISTINCT tbl_filedetails.vfilepathc
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?
SELECT tbl_filedetails.vfilepathc lient, sum(distinct tbl_filedetails.iactualsiz e)
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.vfilepathc lient
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.vfilepathc
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.ia ctualsize)
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.vfilep athclient
and y.vuserrid=u.vuserid
)
note exists syntax can perform better than in syntax
hth
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.ia
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.vfilep
and y.vuserrid=u.vuserid
)
note exists syntax can perform better than in syntax
hth
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SELECT tbl_filedetails.vfilepathc
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.vfilepathc
Regards,
Patrick