SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question MySql Query Count_Working_Days

    I have Emp table with following values

    Code:
    Emp_Id  Emp_Name    Subject        Dates
    001      Smith      Java         07-02-2012
    001      Smith      oracle       08-02-2012
    001      smith      C++          10-02-2012
    002      john       java         01-01-2012
    002      john       SE           10-01-2012
    002      john       c            10-01-2012  
    001      smith      physics      04-01-2012
    001      smith      c#           07-02-2012
    001      smith     javascript    07-02-2012
    Now as we can see here smith studied only 3 days for month February and 1 for month Jan while john studied only 2 days for month January.

    How can we calculate this count for any employee? As a e.g:Output should be in following way.

    Code:
    Emp_Id   Emp_Name  Month_Year   No_Of_Days_Studied_In_Month
    001      smith      Feb12                 3
    001      smith      Jan12                 1
    002      john       Jan12                 2

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    What have you got so far?

  3. #3
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SELECT Emp.Emp_Name,COUNT(Emp.date),DATE_FORMAT(Emp.date,'%b%y')AS Dates FROM Emp GROUP BY DATE_FORMAT(Emp.date,'%b'),Emp.Emp_Name

    I have tried this query, but its giving me output like this:
    Code:
    EMP_NAME	COUNT(EMP.DATE)	               DATES
    smith    	      5	                        Feb12
    john	              3	                        Jan12
    smith	              1	                        Jan12

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,322
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    you want COUNT(DISTINCT emp.date), not COUNT(emp.date)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's working!!!!!!

    Thnks.......


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •