You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求编写MySQL JOIN查询语句获取指定项目的开发者工时等信息

Solution for MySQL JOIN Query to Fetch Developer Work Details

Hey there! Let's break this down step by step to get you the exact query you need. First, I'll assume your database uses these common table structures (adjust if your actual schema differs):

  • projects: Stores project core data (project_id, project_name, lead_user_id → the user ID of the project's responsible lead)
  • users: Holds user information (user_id, username → to identify individual developers)
  • developer_worklogs: Tracks each developer's project contributions (worklog_id, project_id, developer_user_id, working_hours, overtime_hours, descriptions, contributions)

The JOIN Query

Here's the query that meets your requirement, with comments to clarify each part:

SELECT
    u.username AS developer_name,
    dw.working_hours AS workingHours,
    dw.overtime_hours AS Overtime,
    dw.descriptions AS Descriptions,
    dw.contributions AS Contributions
FROM
    projects p
JOIN
    developer_worklogs dw ON p.project_id = dw.project_id
JOIN
    users u ON dw.developer_user_id = u.user_id
WHERE
    -- Restrict access to only the lead's own project
    p.lead_user_id = 123 -- Replace with the logged-in lead's user ID
    AND
    -- Target the specific project the lead wants to view
    p.project_id = 456; -- Replace with the target project ID

Key Details to Adjust for Your Schema:

  • Security: Always use parameterized queries (instead of hardcoding IDs) in your application to avoid SQL injection. For example, use ? placeholders in Java prepared statements or %s in Python's MySQL connectors.
  • Table/Column Names: Swap out identifiers like developer_worklogs or working_hours to match your actual database schema.
  • Including Inactive Developers: If you want to show developers assigned to the project but with no work logs yet, replace JOIN with LEFT JOIN between projects and developer_worklogs (you'll get NULL values for their work fields).

Example Output (Matching Your Requested Format):

developer_nameworkingHoursOvertimeDescriptionsContributions
jane_doe405Fixed payment gateway bugsImplemented 3 core features
john_smith382Updated API documentationOptimized database queries

内容的提问来源于stack exchange,提问作者Sachith Wickramaarachchi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:19:03