Author |
Topic |
Rliss
Starting Member
31 Posts |
Posted - 2006-08-03 : 17:14:11
|
Query:select top 10 [LINKSET_NAME] ,[START_DATE_TIME] ,[HIGH_PCT_OCCUPANCY]FROM [LinkOccupancy].[dbo].[LINKSET_DAILY_HIGH_VIEW]where start_date_time >= '3/1/2006' and start_date_time <= '3/31/2006'order by high_pct_occupancy desc Results:LINKSET_NA START_DATE_TIME PCT_O------------ ----------------------------- -----LINKSET010 2006-03-10 20:15:00.000 47.73LINKSET007 2006-03-19 07:00:00.000 47.69LINKSET004 2006-03-07 09:30:00.000 47.61LINKSET004 2006-03-18 16:45:00.000 47.60LINKSET010 2006-03-30 14:00:00.000 47.52LINKSET005 2006-03-05 15:30:00.000 47.48LINKSET010 2006-03-09 02:15:00.000 47.45LINKSET012 2006-03-08 09:00:00.000 47.44LINKSET003 2006-03-18 23:30:00.000 47.43LINKSET006 2006-03-13 09:00:00.000 47.38Is there a way to keep a linkset_name from repeating? distinct doesn't work.Thanks,RLiss |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-08-03 : 17:51:42
|
"Is there a way to keep a linkset_name from repeating? distinct doesn't work."What is your expected result ? KH |
|
|
Rliss
Starting Member
31 Posts |
Posted - 2006-08-03 : 17:58:30
|
The result I want is the top 10 Linksets ( the 10 linksets with the highest occupancy, 10 different linksets, it is not a true top 10 list when I get 7 linksets where some of them repeat) RLiss |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-08-03 : 18:18:16
|
[code]select top 10[LINKSET_NAME],[START_DATE_TIME],[HIGH_PCT_OCCUPANCY]FROM [LinkOccupancy].[dbo].[LINKSET_DAILY_HIGH_VIEW]where start_date_time >= '3/1/2006' and start_date_time <= '3/31/2006'GROUP BY LINKSET_NAMEorder by high_pct_occupancy desc[/code] KH |
|
|
Rliss
Starting Member
31 Posts |
Posted - 2006-08-03 : 18:21:17
|
I apologize, I also need the corresponding data for the linkset... |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-08-03 : 18:27:20
|
But which one do you need ? the one with max (high_pct_occupancy desc) ?LINKSET010 2006-03-10 20:15:00.000 47.73LINKSET010 2006-03-30 14:00:00.000 47.52LINKSET010 2006-03-09 02:15:00.000 47.45 KH |
|
|
Rliss
Starting Member
31 Posts |
Posted - 2006-08-03 : 18:39:56
|
yes, the one with the max(high_occupancy)RLiss |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-08-03 : 19:41:22
|
try this. . .select [LINKSET_NAME], [START_DATE_TIME], [HIGH_PCT_OCCUPANCY]from [LinkOccupancy].[dbo].[LINKSET_DAILY_HIGH_VIEW]inner join( select top 10 [LINKSET_NAME], max(high_pct_occupancy) as max_occupancy from @table where . . . group by [LINKSET_NAME] order by max(high_pct_occupancy) desc) mon t.[LINKSET_NAME] = m.[LINKSET_NAME]and t.high_pct_occupancy = m.max_occupancy KH |
|
|
Rliss
Starting Member
31 Posts |
Posted - 2006-08-04 : 11:26:16
|
This worked... now I have to clean it up..select a.[LINKSET_NAME], a.[START_DATE_TIME], a.[HIGH_PCT_OCCUPANCY]from [LinkOccupancy].[dbo].[LINKSET_DAILY_HIGH_VIEW] ainner join( select top 10 m.[LINKSET_NAME], max(m.high_pct_occupancy) as max_occupancy from [LinkOccupancy].[dbo].[LINKSET_DAILY_HIGH_VIEW] as m where m.start_date_time >= '3/1/2006' and m.start_date_time <= '3/31/2006' group by m.[LINKSET_NAME] order by max(m.high_pct_occupancy) desc) ton a.[LINKSET_NAME] = t.[LINKSET_NAME]and a.high_pct_occupancy = t.max_occupancywhere a.start_date_time >= '3/1/2006' and a.start_date_time <= '3/31/2006'order by a.[HIGH_PCT_OCCUPANCY] descI had to duplicate the where clause because I picked up a record from a different date range with the same pct_occupancy, a highly unlikely occurance, but better to catch this in test.Thanks... |
|
|
|