-
Jul 16th, 2020, 08:54 PM
#1
Thread Starter
Addicted Member
MySQL Query Help
I am looking for the correct syntax for a MySQL query. I need to select all the duration times from each unique user name.
SELECT username, durationtime FROM mcc3dumdb.tbleusage WHERE???
I know the basics of MySQL but advanced queries throw me as I dont use it often. I can take the query above (minus the WHERE), and return all entries, create the data adapter, and fill the data table. And then bind the table to a data grid view. I just need help figuring out the best way to get the average duration for each user.
In the attached image, imagine all the start, end, and duration times were different. I would like to: For Each User get all the durations. eg. all duration for jsmith, all durations, for jappleseed, etc.
I will eventually calculate the average duration for each user and in a data grid view display the user name once and the average duration. Only two columns in the DGV. If this is easier done as another table in MySQL I open to that as well but would need a little guidance on how to set that up.
I hope I explained that well. Thank you in advance.
-
Jul 16th, 2020, 09:14 PM
#2
Re: MySQL Query Help
Questions about SQL are not questions about VB.NET. SQL is the same no matter the language used to write the application that connects to the database. I have asked the mods to move this thread to the Database Development forum.
-
Jul 16th, 2020, 09:32 PM
#3
Thread Starter
Addicted Member
Re: MySQL Query Help
Originally Posted by jmcilhinney
Questions about SQL are not questions about VB.NET. SQL is the same no matter the language used to write the application that connects to the database. I have asked the mods to move this thread to the Database Development forum.
My apologies, thank you very much.
-
Jul 16th, 2020, 09:32 PM
#4
Re: MySQL Query Help
A WHERE clause is a filter, i.e. it includes some records and excludes others based on one or more criteria. Is that what you actually want to do? It doesn't sound like it, so a WHERE clause is probably not what you need. If you're saying that you want to group multiple rows with the same UserName into one with the average of their Duration values then you want a GROUP BY clause and the appropriate aggregate function. I don't use MySQL much so don't know all the specific syntax but most databases will have an AVG or AVERAGE aggregate function. Ten seconds on the web searching for "mysql average" tells me that it's the former. I suggest that you research that and the GROUP BY clause.
-
Jul 17th, 2020, 07:04 AM
#5
Re: MySQL Query Help
Thread moved to the 'Database Development' forum - which is where you should always post SQL questions (while SQL can be used in VB.Net, it is certainly not specific to VB.Net)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|