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 |
|
mohan g
Starting Member
1 Post |
Posted - 2004-08-19 : 15:09:19
|
| i need some help in building an SQL query (to show the result in a crystal report ver. 9.0)i am doing a real time project.i have to log the statuses (ON/OFF) of each bulb continuously and i store the data in a table (i have given the sample data) sql server2000 DB table.i want the latest 'ON' (glowing) time of each bulb. i.e the difference between the "latest" ON and OFF changetimes. if the query is not possible to build then is there any other way to get the result and show in a crystal report ?please help me to get the resultthanx in advanceMohan GBulbNo State ChangeTime 2 ON 19/08/2004 21:22:102 OFF 19/08/2004 21:20:104 ON 19/08/2004 21:18:504 OFF 19/08/2004 21:17:007 ON 19/08/2004 21:12:507 OFF 19/08/2004 21:12:409 ON 19/08/2004 21:12:309 OFF 19/08/2004 21:11:0010 ON 19/08/2004 21:12:3010 OFF 19/08/2004 21:11:002 ON 19/08/2004 20:22:102 OFF 19/08/2004 20:20:105 ON 19/08/2004 20:12:305 OFF 19/08/2004 20:11:007 ON 19/08/2004 20:12:507 OFF 19/08/2004 20:12:409 ON 19/08/2004 20:12:309 OFF 19/08/2004 20:11:00The result should be : to show the lastest total ON time BulbNo State UP Time (in seconds)2 ON 1204 ON 1105 ON 907 ON 109 ON 9010 ON 90 |
|
|
mk_garg20
Constraint Violating Yak Guru
343 Posts |
Posted - 2004-08-19 : 19:25:06
|
| Do you have any primary key on the table?mk_garg |
 |
|
|
ehorn
Master Smack Fu Yak Hacker
1632 Posts |
Posted - 2004-08-19 : 19:34:35
|
| [code]select bo.bulbno,'On' as state, abs(datediff(ss,max(bo.changetime),max(bi.changetime))) uptimefrom bulblog bojoin bulblog bi on bi.bulbno = bo.bulbnowhere bo.state = 'On' and bi.state='Off'group by bo.bulbno[/code] |
 |
|
|
|
|
|