July 9, 2010 at 6:44 am
Hi all,
how to DISTINCS two fields in database ?
in the database i have diferent values for percentage and usernames, but i want the last for each user
SELECT DISTINCT(dbo.OSUSR_A7L_USER_MASTER.NAME),
dbo.OSUSR_BZA_USER_LOGIN_DAY.USERPROFILEPERCENTAGE,
dbo.OSUSR_A7L_GROUP.NAME AS GRUPO
FROM dbo.OSUSR_A7L_USER_MASTER LEFT JOIN dbo.OSUSR_BZA_USER_LOGIN_DAY
ON dbo.OSUSR_A7L_USER_MASTER.ID=dbo.OSUSR_BZA_USER_LOGIN_DAY.USERMASTERID
LEFT JOIN dbo.OSUSR_A7L_GROUP
ON dbo.OSUSR_A7L_USER_MASTER.GROUPID = dbo.OSUSR_A7L_GROUP.ID
WHERE NOT dbo.OSUSR_BZA_USER_LOGIN_DAY.USERPROFILEPERCENTAGE = ' '
AND dbo.OSUSR_A7L_USER_MASTER.ISACTIVE='TRUE'
GROUP BY dbo.OSUSR_BZA_USER_LOGIN_DAY.USERPROFILEPERCENTAGE,
dbo.OSUSR_A7L_USER_MASTER.NAME,
dbo.OSUSR_A7L_GROUP.NAME
ORDER BY dbo.OSUSR_A7L_USER_MASTER.NAME , dbo.OSUSR_BZA_USER_LOGIN_DAY.USERPROFILEPERCENTAGE DESC
July 9, 2010 at 9:04 am
You're going to need to be more specific on what you want. Can you provide table layouts, sample data and expected results? See the first link in my signature block on how to post to this site
For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
July 9, 2010 at 9:42 am
THanks for the help, but resolve the problem 🙂
SOLUTION 😀
SELECT
MAX(CONVERT(INT, dbo.OSUSR_BZA_USER_LOGIN_DAY.USERPROFILEPERCENTAGE))AS PERCENTE,
dbo.OSUSR_A7L_GROUP.NAME AS GRUPO,
dbo.OSUSR_A7L_USER_MASTER.NAME AS NAMEs
FROM dbo.OSUSR_A7L_USER_MASTER LEFT JOIN dbo.OSUSR_BZA_USER_LOGIN_DAY
ON dbo.OSUSR_A7L_USER_MASTER.ID=dbo.OSUSR_BZA_USER_LOGIN_DAY.USERMASTERID
LEFT JOIN dbo.OSUSR_A7L_GROUP
ON dbo.OSUSR_A7L_USER_MASTER.GROUPID = dbo.OSUSR_A7L_GROUP.ID
WHERE NOT dbo.OSUSR_BZA_USER_LOGIN_DAY.USERPROFILEPERCENTAGE = ' '
AND dbo.OSUSR_A7L_USER_MASTER.ISACTIVE='TRUE'
GROUP BY
dbo.OSUSR_A7L_USER_MASTER.NAME,
dbo.OSUSR_A7L_GROUP.NAME
ORDER BY dbo.OSUSR_A7L_USER_MASTER.NAME DESC
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply