Solved

Need help with a mysql select statement

Posted on 2012-03-13
6
537 Views
Last Modified: 2012-06-27
Hi Experts
I have written a query and I am not sure where I have gone wrong.
What we need to achieve is:
1) we need to see how much Time_used id assigned to each project our team is working on.

however in my query I am unable to get the sum of hours assigned to each project.
I am ending up with the sum of all hours assigned to the user.

Sum(theme_keywords_pyramidpromo_assigned.TaskTimeSingle) is the column that holds all the hours assigned per project.

project = theme_keywords_pyramidpromo_assigned.profileid

user  =  usrprofiles.usrid

basically all i need to have the "Time_used" per project, per user for the month and any other work not finished in previous months.

in the attached txt file you will see that in the Time_used column rows 1,2 the values are the same

see column profile Name
credit repair
sarahdacruz.com

both are = 86

they should be
credit repair = 83
sarahdacruz.com = 3

Any suggestions will be appreciated

Query
======
SELECT
      usrprofiles.Department AS Department,
      usrprofiles.Email AS Email,
      usrprofiles.Title AS Title,
      usrprofiles.FirstName AS FirstName,
      usrprofiles.Surname AS Surname,
      projectprofile.profileName AS profileName,
      usrprofiles.AvailabilityDaysInMonth AS AvailabilityDaysInMonth,
      usrprofiles.AvailabilityHoursInDay AS AvailabilityHoursInDay,
      (usrprofiles.AvailabilityDaysInMonth * usrprofiles.AvailabilityHoursInDay)AS TotalHours,
      (SELECT Sum(theme_keywords_pyramidpromo_assigned.TaskTimeSingle)FROM theme_keywords_pyramidpromo_assigned WHERE theme_keywords_pyramidpromo_assigned.usrid = usrprofiles.usrid and theme_keywords_pyramidpromo_assigned.profileid = theme_keywords_pyramidpromo_assigned.profileid) AS Time_used,
      round(((usrprofiles.AvailabilityDaysInMonth * usrprofiles.AvailabilityHoursInDay) - sum(theme_keywords_pyramidpromo_assigned.TaskTimeSingle)), 2)AS Hour_Left
FROM
      usrprofiles
JOIN theme_keywords_pyramidpromo_assigned ON theme_keywords_pyramidpromo_assigned.usrid = usrprofiles.usrid
JOIN projectprofile ON projectprofile.profileid = theme_keywords_pyramidpromo_assigned.profileid
WHERE
usrprofiles.CompanyID = usrprofiles.CompanyID
AND theme_keywords_pyramidpromo_assigned.completed = 0
AND(MONTH(theme_keywords_pyramidpromo_assigned.dateDue) <= MONTH(now()))
AND(YEAR(theme_keywords_pyramidpromo_assigned.dateDue) = YEAR(now()))
GROUP BY
usrprofiles.usrid,
theme_keywords_pyramidpromo_assigned.profileid,
projectprofile.CompanyID
team-time-management.txt
0
Comment
Question by:matthewdacruz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 

Author Comment

by:matthewdacruz
ID: 37714127
No one know how to do this type of query?
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 37714355
I am not really into complex SQL queries, I would do this as a series of simple queries from PHP. Having said that, your GROUP BY has user as the primary grouping, should it not have the project as the primary grouping?

GROUP BY
projectprofile.CompanyID,
usrprofiles.usrid,
theme_keywords_pyramidpromo_assigned.profileid

rather than

GROUP BY
usrprofiles.usrid,
theme_keywords_pyramidpromo_assigned.profileid,
projectprofile.CompanyID
0
 

Author Comment

by:matthewdacruz
ID: 37714437
Hi bportlock
We need the GROUP BY usrprofiles.usrid, as there are multiple people working on a particular project. I f we group by just theme_keywords_pyramidpromo_assigned.profileid,
projectprofile.CompanyID then all of the team get lumped under a project.

We wanting to manage the teams workload and see what they currently working on.
Maybe there is a better way of writing the query I have?
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Accepted Solution

by:
matthewdacruz earned 0 total points
ID: 37714473
Got it figured out, it was the nested select that caused the issues.
should have just been  

Sum(theme_keywords_pyramidpromo_assigned.TaskTimeSingle)

instead of

 (SELECT Sum(theme_keywords_pyramidpromo_assigned.TaskTimeSingle)FROM theme_keywords_pyramidpromo_assigned WHERE theme_keywords_pyramidpromo_assigned.usrid = usrprofiles.usrid and theme_keywords_pyramidpromo_assigned.profileid = theme_keywords_pyramidpromo_assigned.profileid) AS Time_used,
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 37714652
Glad you are sorted out.
0
 

Author Closing Comment

by:matthewdacruz
ID: 37734351
I am closing this request as I figured out the issue.
The nsested select statement resulted in the wrong totals being found
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question