Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 help needed in group by with order by

Author  Topic 

sqllover
Constraint Violating Yak Guru

338 Posts

Posted - 2008-04-15 : 05:50:30
hi,

my table data:

Sensor_Serial_No date_time Attribute_Flag
-----------------------------------------------------
2 2008-03-03 01:00:00 5
2 2008-03-03 06:00:00 5

my result should be like this

Sensor_Serial_No no of times occured Attribute_Flag lastoccurence

2 2 5
2008-03-03 06:00:00

please give me query for this please

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-15 : 05:58:16
[code]SELECT Sensor_Serial_No,COUNT(*) AS [no of times occured],Attribute_Flag,MAX(date_time) AS lastoccurence
FROM YourTable
GROUP BY Sensor_Serial_No,Attribute_Flag[/code]
Go to Top of Page

sqllover
Constraint Violating Yak Guru

338 Posts

Posted - 2008-04-15 : 06:02:26
thank you friend
Go to Top of Page
   

- Advertisement -