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 |
|
simflex
Constraint Violating Yak Guru
327 Posts |
Posted - 2007-03-09 : 21:55:38
|
| hi all,This really should not be a problem but I have 2 issues I can't seem to get right.I have a table call Downloads with the following field names:DownloadID - identityTitle - nvarchar, 255FileName - nvarchar, 255 Downloads - intDateDownloaded - Date/TimeI wanted to display 3 different types of results:1, Most view file2, Daily File views3, Nost Viewed by DateMy query for the first one:Select filename, MAX(Downloads) from DownloadsI was look for results like:File Name Total ViewFile1 35Just the most viewed file, nothing elseThe second one, my query looks like this:Select downloadDate, file, title, count(downloads) from downloadsI expected results like:File Name Title Date # of downloadsfile1 turtle ninja 03/08/2007 3file2 Pebble Beach 03/08/2007 2etcetcLastly, I want to know most viewed by date.I didn't try this since the first 2 weren't producing the correct results.Any assistance for any or all would be greatly, greatly appreciated. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-09 : 23:45:56
|
1. Most view fileselect *from Downloads d where d.downloads = (select max(downloads) from Downloads) 2. Daily File viewsselet filename, title, downloadDate, count(downloads) as [total downloads]from downloadsgroup by filename, title, downloadDate, 3. Most Viewed by Dateselect downloadDate, filename, downloads from Downloads dwhere filename = (select top 1 filename from downloads x where x.downloaddate = d.downloaddate order by downloads desc) KH |
 |
|
|
simflex
Constraint Violating Yak Guru
327 Posts |
Posted - 2007-03-10 : 08:51:35
|
| hi Khtan and thanks for your response.I am not getting the result I am expecting.I was hoping to see something like:Most Downloaded / Viewed FileFile Name # of times Downloaded / ViewedNinja 5Instead all the files are listed.For instance, there are 3 files downloaded (just for testing)2 are downloaded once each and the 3rd has been downloaded 5 times.Instead all 3 files are listed and the one that is downloaded 5 times is listed 5 times. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-10 : 08:55:31
|
it will be easier if you can provide the table structure, sample data and the expected result KH |
 |
|
|
simflex
Constraint Violating Yak Guru
327 Posts |
Posted - 2007-03-10 : 10:07:16
|
| ok,Here is the table structure and it is the same I provided when I first posted this question:DownloadID - identityTitle - nvarchar, 255FileName - nvarchar, 255 Downloads - intDateDownloaded - Date/Timetypical data:Download ID Title File Name Downloads Date Downloaded1 title1 file1 1 2/25/20072 title1 file1 1 2/25/20073 title1 file1 1 2/25/20074 title2 file2 1 2/25/2007etcetcNow, if I need to know the most downloaded, I was hoping to show that file1 is the most downloaded = downloaded 3 timesIf I need to change the structure a little bit, can you please tell me what to change?Thanks for your assistance |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-10 : 18:12:56
|
most downloaded :select top 1 FileName, total_downloads = sum(Downloads)from Downloadsgroup by Filenameorder by total_downloads desc KH |
 |
|
|
simflex
Constraint Violating Yak Guru
327 Posts |
Posted - 2007-03-10 : 22:11:12
|
| Thank you very much, that worked! |
 |
|
|
|
|
|
|
|