Link to home
Start Free TrialLog in
Avatar of lulu50
lulu50Flag for United States of America

asked on

SQL (Group by)

Hi,

I have a select statement that I just want to group by

EditTime and AppID

instead of grouping by

      EditTime
    , AppID
    , AppName
    , MajorUpgradeCost
    , PlannedUpgradeYear
    , UpgradeStrategy
    , SoftwareVersion
    , OldestVersionSupportedBySupplier
    , EmployeeName

but I do want to select all the above field but I just want to group by the "EditTime" and "AppID"
How can I do this?

SELECT
      EditTime
    , AppID
    , AppName
    , MajorUpgradeCost
    , PlannedUpgradeYear
    , UpgradeStrategy
    , SoftwareVersion
    , OldestVersionSupportedBySupplier
    , EmployeeName
FROM EDIT_ApplicationDescription
WHERE ((datalength(SoftwareVersion)!=0) and ((SoftwareVersion != '')  or (SoftwareVersion IS NOT NULL) or (SoftwareVersion <> '')))
or  
 ((datalength(MajorUpgradeCost)!=0) and ((MajorUpgradeCost != '')  or (MajorUpgradeCost IS NOT NULL) or (MajorUpgradeCost <> '')))
or 
((datalength(PlannedUpgradeYear)!=0) and ((PlannedUpgradeYear != '')  or (PlannedUpgradeYear IS NOT NULL) or (PlannedUpgradeYear <> '')))
or
((datalength(UpgradeStrategy)!=0) and ((UpgradeStrategy != '')  or (UpgradeStrategy IS NOT NULL) or (UpgradeStrategy <> '')))
or 
((datalength(OldestVersionSupportedBySupplier)!=0) and ((OldestVersionSupportedBySupplier != '')  or (OldestVersionSupportedBySupplier IS NOT NULL) 
or (OldestVersionSupportedBySupplier <> '')))
group by AppID, EditTime, AppName
    , MajorUpgradeCost
    , PlannedUpgradeYear
    , UpgradeStrategy
    , SoftwareVersion
    , OldestVersionSupportedBySupplier
    , EmployeeName
order by EditTime desc

Open in new window

Avatar of Jim Horn
Jim Horn
Flag of United States of America image

>but I do want to select all the above field but I just want to group by the "EditTime" and "AppID"
Just a thought, I don't see any aggregate functions like SUM(), MIN(), MAX(), COUNT(), etc., so why are we grouping in the first place?

If you only want to return unique rows, change SELECT to SELECT DISTINCT.

If there's something else you need, spell it out in this question, specifically 'I want to do {x} with {all columns other than {"EditTime" and "AppID"}'
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lulu50

ASKER

Thank you Scott!!!
Avatar of lulu50

ASKER

I've requested that this question be closed as follows:

Accepted answer: 0 points for lulu50's comment #a40504423

for the following reason:

Thanks
Avatar of lulu50

ASKER

Thank you