Results 1 to 5 of 5

Thread: MySQL Query Help

  1. #1

    Thread Starter
    Addicted Member dprontnicki's Avatar
    Join Date
    Sep 2016
    Posts
    151

    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.

    Name:  MySQL_Example.jpg
Views: 365
Size:  57.3 KB

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    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.

  3. #3

    Thread Starter
    Addicted Member dprontnicki's Avatar
    Join Date
    Sep 2016
    Posts
    151

    Re: MySQL Query Help

    Quote Originally Posted by jmcilhinney View Post
    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.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    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.

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    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
  •  



Click Here to Expand Forum to Full Width