| View previous topic :: View next topic |
| Author |
Message |
Bpk. Adi Wira Kusuma Guest
|
Posted: Mon Jul 25, 2005 2:03 am Post subject: Help me? |
|
|
I've data like this
noid fdate ftime fstatus
---------------------------------------
1 1/1/2005 1/1/2005 6:30:00 1
1 1/1/2005 1/1/2005 6:30:00 1
1 1/1/2005 1/1/2005 6:31:00 1
1 1/1/2005 1/1/2005 16:30:00 1
1 1/1/2005 1/1/2005 16:30:00 0
1 1/1/2005 1/1/2005 16:33:00 0
1 1/1/2005 1/1/2005 16:33:00 0
2 1/1/2005 1/1/2005 6:27:00 1
2 1/1/2005 1/1/2005 6:28:00 1
2 1/1/2005 1/1/2005 6:32:00 1
2 1/1/2005 1/1/2005 16:30:00 0
2 1/1/2005 1/1/2005 16:31:00 0
2 1/1/2005 1/1/2005 16:45:00 0
2 1/1/2005 1/1/2005 16:45:00 0
I want to delete. if fstatus =1 so fisrt record (min(Ftime)) of group
noid,fdate is not deleted. but if fstatus =0 so last record (max(Ftime)) of
group noid,fdate is not deleted. So its data will be;
noid fdate ftime fstatus
---------------------------------------
1 1/1/2005 1/1/2005 6:30:00 1
1 1/1/2005 1/1/2005 16:33:00 0
2 1/1/2005 1/1/2005 6:27:00 1
2 1/1/2005 1/1/2005 16:45:00 0
Can u help me? How sintax sql? Can it be solved with one statement?
|
|
| Back to top |
|
 |
Yannis Guest
|
Posted: Mon Jul 25, 2005 5:57 am Post subject: Re: Help me? |
|
|
"Bpk. Adi Wira Kusuma" <adi_wira_kusuma (AT) yahoo (DOT) com.sg> wrote in
news:42e44c73 (AT) newsgroups (DOT) borland.com:
| Quote: | Can u help me? How sintax sql? Can it be solved with one statement?
|
Try the following sql
Delete From Table1 T1 where (FStatus = 1 and FTime >(Select min(Ftime) from
Table1 T2 Where T2.noid = T1.noid and T2.Fdate = T1.Fdate)) OR (FStatus = 0
and FTime < (Select max(Ftime) from Table1 T3 Where T3.noid = T1.noid and
T3.Fdate = T1.Fdate))
I think it will do the job
Disclaimer :
The above statement has been keyed in directly to the news client and never
tested on any sql server. It has been written with a background of MSSQL
server and I do not know if it will work on any other server.
Changes probably required in order to make it work for your purposes.
Regards
Yannis.
|
|
| Back to top |
|
 |
|