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.
| Author |
Topic |
|
ragh
Starting Member
34 Posts |
Posted - 2005-02-14 : 03:57:00
|
| Hi,I got some rows like :SNo ID Name Date TimeIn TimeOut TWH Duration1 0005 Ragh 01/31/2005 15:32 15:36 240 00:042 0005 Ragh 01/31/2005 15:38 15:39 60 00:053 0005 Ragh 01/31/2005 15:40 16:01 1260 00:261 0005 Ragh 02/01/2005 09:00 09:01 60 00:011 0006 ASDF 02/01/2005 09:00 09:01 60 00:01Now, i want to take only the maximum duration data and delete rest of them for that particular date and a particular ID.The SNo is increased accordingly to ID and to Date. so the MAX(SNo) will be the total duration for that particular date.How can i achieve this Query, i want to display a group report in VB Data reports.Kindly help me !!!Ragh |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-02-14 : 04:20:22
|
| Delete from Table where Sno not in (Select Max(Sno) from Table where Sno>1 group by ID,Date)Madhivanan |
 |
|
|
ragh
Starting Member
34 Posts |
Posted - 2005-02-14 : 04:53:56
|
| Nooooo....I want to take that SNo 3 and then porceed to SNo 1 of next date and so on...there can be SNo = 1 also per date for ID. so what to do ?Ragh |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-02-14 : 05:22:32
|
| Try thisSELECT * FROM table TWHERE SNo in ( Select max(SNo) from table where id=T.id and Date=T.Date group by Sid, Date)Madhivanan |
 |
|
|
ragh
Starting Member
34 Posts |
Posted - 2005-02-14 : 05:24:19
|
| Like this i want in my VB Reports....SELECT id,date,name,twhFROM grtableORDER BY id,date,twhCOMPUTE SUM(twh) BY id,dateid date name twh ----- ---------- ----- ----------- 0005 2005-01-31 Ragh 600005 2400005 1560 sum =========== 18600005 2005-01-31 Ragh 60 sum =========== 60COMPUTE BY Doesnt work in ACCESS VB :(Ragh |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-02-14 : 05:37:15
|
| SELECT id,date ,name,twh, (Select sum(amount) from grTable where id=T.id and date=t.date group by id,date) FROM grTable AS TWHERE SNo in ( Select max(SNo) from grTable where id=T.id and date=T.date group by id,date )Madhivanan |
 |
|
|
|
|
|
|
|