|
Try a sub query that finds max [Last Played] by Count.
select ...
from songlist
inner join (select count, max([last played])...
If you need more let me know.
djj
|
|
|
|
|
Sorry I was pressed for time.
The sub query should be something like:
SELECT top 10 A.artist, A.title, A.count_played, B.MaxDate
FROM dbo.songlist A
INNER JOIN (
SELECT count_played, MAX(date_title_played) AS MaxDate
FROM dbo.songlist
GROUP BY count_played
) AS B
ON A.date_title_played = B.MaxDate
WHERE count_played >0
ORDER BY count_played DESC, date_title_played DESC
This most likely will not run but again as this is of the top of my head. The join condition (ON) may need work.
|
|
|
|
|
Sorry so long with this reply I also get pressed with work time unfortunately.
I tried the suggested query and have now got it running fine, for this I thank you, however I do have a small issue and can't seem to find the answer to it.
If 2 songs exist with the same name
i.e.
"only you" by the flying pickets which has 47 plays
"only you" by the platters which has 14 plays
It will show both even though 14 plays does not fit with the top 5 most played
I slightly altered you code to fit my needs as follows...
SELECT top 5 A.artist, A.title, A.count_played, B.MaxDate FROM dbo.songlist A INNER JOIN (SELECT count_played, MAX(date_title_played) AS MaxDate
FROM dbo.songlist GROUP BY count_played ) AS B ON A.date_title_played = B.MaxDate
WHERE B.count_played >0
ORDER BY B.count_played DESC, date_title_played DESC
Any ideas ?
Thanks in advance
|
|
|
|
|
Try a sub query (top 5) that is grouped by title and ordered by number of plays.
Let me think about this and hopefully get back to you soon.
djj
|
|
|
|
|
How do I update a date/time field in a Microsoft Access database using SQL ?
I am using VB .net and up to now all my sql statements work fine.
I have tried several variations of this statement but none work. They all give me a generic "Error in UPDATE statement" message.If i try any other column of my database, the UPDATE statement works fine.It only has a problem with the TIME field which is declared in the database as DATE/TIME.
For instance the following will NOT work.
UPDATE tablename SET timecolumn='12:34' where id=82
|
|
|
|
|
Never mind.I figured it out.
I needed brackets for the time field.
So it should be :
UPDATE tablename SET [time]='12:34' where id=80
|
|
|
|
|
Hi all,
I am having a table in which one field data type is text and the data stored in it is characters + numbers for example SD01TU9,SD01TU8,SD01TU10.
Now the problem is i want the max from it.As in the above example the max should show SD01TU10 but when i use max function on that field it shows SD01TU9.
Please any one can solve it.
Thanks in advance.
|
|
|
|
|
You have a number of choices, you have a requirement to do numerical operations on a field with mixed data.
Create another field and extract the numeric component from the mixed field
Use a view (query in Access I think) to do the same thing just don't store it
Go back to your initial design that put the mixed data in there and address the problem at the source.
As your data seems to be consistent (SD and TU) you could do this with nested replace statements. It gets a little tricky if your text data changes from the standard, then use regex.Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Are you stalking me?
|
|
|
|
|
If all the strings include the letters "TU" before the numbers at the end, you could use a combination of instr() and len() and right() to get what you need...
I'm doing this from memory and without access to Access to test, but it would be something like this:
clng(right(FIELDNAME, len(FIELDNAME)-instr(FIELDNAME, "TU")))
Which basically says locate the position of TU in the field, then take the characters to the right of them, convert to long and then you can happily find the max of those numbers.
|
|
|
|
|
If you have the option, you might consider ensuring that the data all have the same number of digits at end.
E.g. use SD01TU09 instead of SD01TU9, or SD01TU009 if there can be three digits.
This would mean you don't have to monkey around with substrings.Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Hi everyone,
I'm creating a database installer where I have some code to create database, tables, stored procedures, etc.
I don't have problems when creating the database, tables and inserting required data. My problem is when my code gets to the stored procedures section.
Here is what I do:
I have different text files (database.txt, tables.txt, insertdata.txt, storeprocedures.txt) where my sql syntax is located.
I execute every process/text file using the following:
ExecuteSql("master", GetSql("database.txt")) ' Creating 1 database.
ExecuteSql("mynewdatabase", GetSql("tables.txt")) ' Creating 15 tables.
ExecuteSql("mynewdatabase", GetSql("insertdata.txt")) ' Inserting data to many tables.
ExecuteSql("mynewdatabase", GetSql("storeprocedures.txt")) ' Creating 6 stored procedures.
Here is part of the error:
In exception handler: Incorrect syntax near the keyword 'PROCEDURE'. "This is the second stored procedure because the variables I get below belong to the second one"
Must declare the scalar variable "@intVariable1".
Must declare the scalar variable "@intVariable1".
Must declare the scalar variable "@intVariable1".
Must declare the scalar variable "@intVariable1".
When trying to create 6 or even 2 stored procedures using the same file ‘storeprocedures.txt' is not possible. If I leave just 1 it works but I really want to keep them together.
Creating 15 tables using the same file 'tables.txt' works, inserting data in different tables using the same file 'insertdata.txt' works.
This is the general syntax I use:
Create Procedure sp_stored1
@intVariablex int
As
Begin
Code
End
Create Procedure sp_stored2
intVariabley int
As
Begin
Code
End
..........
..........
..........
Is is possible to create more than 1 stored procedure the way I'm trying to?
Do I need to end every stored procedure with specific sql syntax, other than the 'end'?
I appreciate your response!!!
Thanks,
Israel
|
|
|
|
|
Try placing GO between each store proc creation script to separate each batch I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Thanks Mark but I have tried that and only works when using the sql editor. I actually had to remove the GO from my other text files (database.txt, tables.txt) in order to work.
Thanks,
Israel
|
|
|
|
|
iramirezp wrote: Create Procedure sp_stored1
@intVariablex int
iramirezp wrote: Create Procedure sp_stored2
intVariabley int
Not sure if this is just a typo, but you seem to be missing a @ in the second Sproc
|
|
|
|
|
It was a typo in the example I put just to have an idea how I have the stored procedures lines.
|
|
|
|
|
have 2 tables:
Table A: code | name
Table B: barcode | name
Table B has full barcode and name, Table A has only code.
I need to run update query that fill name in Table A.
I tried something like:
update A set name = (select top 1 Name from B where B.Code = mid(A.Barcode,1,8))
but it doesn't work.
|
|
|
|
|
update A set name = (select top 1 Name from B where B.barcode = mid(A.code,1,8))
Does that work any better? Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
|
|
|
|
|
'mid' is not a recognized built-in function name.
|
|
|
|
|
Then you will need to find out what built-in function does string extraction and replace 'mid' with that function name. It probable that the parameters will be different to. Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
|
|
|
|
|
and that is one more reason why giving appropriate names to everything is important.
|
|
|
|
|
I have a datagridview control on my win form, pls how do i get it to show multiple tables records.
thanks .
|
|
|
|
|
get your tables from the database
put them all in the same dataset
create the relationships between the tables
set the dataset as the datasource for the DGV
[edit] this belongs in the winforms forum, but the above is the way to do it [/edit]Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I'm preparing an WPF article that creates storages automatically from classes with nesting and else.
The issue is that in the ACCESS db execute , everything works fine but images bigger than 12 KB I get the error:
'System resource exceeded.'
I show the process:
public Database db;
public DBEngine engine;
this.db = this.engine.OpenDatabase(file, Missing.Value, Missing.Value, Missing.Value);
access.db.Execute(String.Concat(query, values), Missing.Value);
in values, the data is directly:
0x89504E47...454E44AE426082
It works with small images, and if I add with the Access directly design it works, so the field type is right, Maybe is an issue with connection size properties. Does any store a big image with DAO12,ADO, or OLEDB with an Insert statement?
Thanks in advance, a great article is coming...
|
|
|
|
|
Whenever I have needed to use images with an Access database, I have always stored the images in the file system and then just a pointer to the image in the database (an url, path or whatever is appropriate for the app). Access does not play well with images when trying to store them in the database.
|
|
|
|