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 |
|
lovekhan12345
Starting Member
2 Posts |
Posted - 2010-08-22 : 02:19:28
|
| HiI have reqiured a query which extract data from the table which is based onmax date & time ,please help meTablename xyzS.no Symbol Date &time Opening rate Current rate1 hbl 21-08-2010 9:15:36 101 1052 hbl 21-08-2010 9:15:40 101 1063 hbl 21-08-2010 9:15:55 101 1044 ppl 21-08-2010 9:15:36 125 1305 ppl 21-08-2010 9:15:40 125 1316 ppl 21-08-2010 9:15:50 125 1287 ppl 21-08-2010 9:15:55 125 126Out put S.no symbol Date & time opening Currnt rate3 hbl 21-08-2010 9:15:36 101 11047 hbl 21-08-2010 9:15:55 125 126only query required for this output |
|
|
slimt_slimt
Aged Yak Warrior
746 Posts |
Posted - 2010-08-22 : 07:20:04
|
try this:selecty.*from(select max(S_no) as s_n ,Symbolfrom XYZgroup by Symbol) as xjoin XYZ as yon x.s_n = y.S_noand x.Symbol = y.Symbol |
 |
|
|
slimt_slimt
Aged Yak Warrior
746 Posts |
Posted - 2010-08-22 : 07:22:54
|
| you need to get the maximum serial_number (S_no) - if this one is unique (i hope), otherwise you'll need to define primary key or unique identifier in your table in order to get the right results. |
 |
|
|
lovekhan12345
Starting Member
2 Posts |
Posted - 2010-08-22 : 09:08:20
|
| Thank u but mistakenly i type two times hblbut i want to on the basis of date and timeHiI have reqiured a query which extract data from the table which is based on max date & time ,please hel p meTablename xyzS.no Symbol Date &time Opening rate Current rate1 hbl 21-08-2010 9:15:36 101 1052 hbl 21-08-2010 9:15:40 101 1063 hbl 21-08-2010 9:15:55 101 1044 ppl 21-08-2010 9:15:36 125 1305 ppl 21-08-2010 9:15:40 125 1316 ppl 21-08-2010 9:15:50 125 1287 ppl 21-08-2010 9:15:55 125 126Out put S.no symbol Date & time opening Currnt rate3 hbl 21-08-2010 9:15:36 101 11047 ppl 21-08-2010 9:15:55 125 126 |
 |
|
|
slimt_slimt
Aged Yak Warrior
746 Posts |
Posted - 2010-08-22 : 10:14:59
|
so it's the same. try this:selecty.*from(select max(date_time) as max_DT ,Symbolfrom XYZgroup by Symbol) as xjoin XYZ as yon x.max_DT = y.date_timeand x.Symbol = y.Symbol |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-08-22 : 12:23:12
|
quote: Originally posted by lovekhan12345 Thank u but mistakenly i type two times hblbut i want to on the basis of date and timeHiI have reqiured a query which extract data from the table which is based on max date & time ,please hel p meTablename xyzS.no Symbol Date &time Opening rate Current rate1 hbl 21-08-2010 9:15:36 101 1052 hbl 21-08-2010 9:15:40 101 1063 hbl 21-08-2010 9:15:55 101 1044 ppl 21-08-2010 9:15:36 125 1305 ppl 21-08-2010 9:15:40 125 1316 ppl 21-08-2010 9:15:50 125 1287 ppl 21-08-2010 9:15:55 125 126Out put S.no symbol Date & time opening Currnt rate3 hbl 21-08-2010 9:15:36 101 11047 ppl 21-08-2010 9:15:55 125 126
sorry didnt get thathow did you get output in blue?datetime value is 21-08-2010 9:15:36 which is not maximum value for hbl. ALso didnt understand how you got 1104 as current charge. can you explain?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
slimt_slimt
Aged Yak Warrior
746 Posts |
Posted - 2010-08-22 : 13:00:12
|
| visakh: i think he made two typo-mistakes. since serial numbers are the highest for each symbol. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-08-22 : 13:06:51
|
quote: Originally posted by slimt_slimt visakh: i think he made two typo-mistakes. since serial numbers are the highest for each symbol.
I too think so but I want him to confirm it ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|