`
yang_kunlun
  • 浏览: 77208 次
  • 性别: Icon_minigender_1
  • 来自: 地球
最近访客 更多访客>>
社区版块
存档分类
最新评论

SQL example

    博客分类:
  • DB
SQL 
阅读更多
SELECT  items.Name AS Name ,
Work_Items AS '#no Workitems',
sec_to_time(Project_Time) AS 'Client/Project Total Time',
sec_to_time(Ticket_project_Time) AS 'Client/Project Time (With Ticket)',
sec_to_time(Total_Hours) AS 'Total Time (not inc breaks)',
Research_Time AS 'Research/Mentoring',
sec_to_time(if(Ticket_project_Time ,
(Project_Time-Ticket_project_Time),Project_Time)) AS 'Client/Project Time (No Ticket)',
sec_to_time(Others_time) AS 'Other' ,
sec_to_time(un_allocated.un_allocated_time) AS 'Un Allocated time'
FROM
(SELECT
count(*) AS Work_Items ,
per.surname AS Name
FROM T4U_WORKITEMS wi
INNER JOIN T4U_DAYINFOS di ON ( wi.dayinfo_id = di.id )
INNER JOIN T4U_TASKS t ON ( wi.task_id = t.id )
INNER JOIN T4U_PROJECTS p ON ( wi.project_id = p.id )
INNER JOIN T4U_PERSONS per ON ( di.person_id = per.id )
WHERE di.daydate  BETWEEN '2009-02-10' AND '2009-02-29'
AND lower(per.surname) LIKE 'eric%'
GROUP BY per.surName) AS items

LEFT JOIN
(
SELECT  per.surname AS Name ,
sum(wi.wEnd-wi.wBegin) AS Project_Time
FROM T4U_WORKITEMS wi
INNER JOIN T4U_DAYINFOS di ON ( wi.dayinfo_id = di.id )
INNER JOIN T4U_TASKS t ON ( wi.task_id = t.id )
INNER JOIN T4U_PROJECTS p ON ( wi.project_id = p.id )
INNER JOIN T4U_PERSONS per ON ( di.person_id = per.id )
INNER JOIN T4U_PROJECTS parent ON ( ifnull(p.parent_id , p.id) = parent.id )
INNER JOIN T4U_PROJECTS grandfather ON ( ifnull(parent.parent_id , parent.id) = grandfather.id )
INNER JOIN T4U_PROJECTS great ON ( ifnull(grandfather.parent_id , grandfather.id) = great.id )
INNER JOIN T4U_PROJECTS root ON ( ifnull(great.parent_id , great.id) = root.id )
WHERE
di.daydate  BETWEEN '2009-02-10' AND '2009-02-29'
AND lower(root.name) = 'projects'
OR lower(root.name) = 'clients'
AND lower(per.surname) LIKE 'eric%'
GROUP BY per.surName) AS project

ON items.Name = project.Name

LEFT JOIN

(SELECT per.surname AS Name ,
t.name AS Task,
sum(wi.wEnd-wi.wBegin) AS Ticket_project_Time
FROM T4U_WORKITEMS wi
INNER JOIN T4U_DAYINFOS di ON ( wi.dayinfo_id = di.id )
INNER JOIN T4U_TASKS t ON ( wi.task_id = t.id )
INNER JOIN T4U_PROJECTS p ON ( wi.project_id = p.id )
INNER JOIN T4U_PERSONS per ON ( di.person_id = per.id )
INNER JOIN T4U_PROJECTS parent ON ( ifnull(p.parent_id , p.id) = parent.id )
INNER JOIN T4U_PROJECTS grandfather ON ( ifnull(parent.parent_id , parent.id) = grandfather.id )
INNER JOIN T4U_PROJECTS great ON ( ifnull(grandfather.parent_id , grandfather.id) = great.id )
INNER JOIN T4U_PROJECTS root ON ( ifnull(great.parent_id , great.id) = root.id )
WHERE
di.daydate  BETWEEN '2009-02-10' AND '2009-02-29'
AND t.name LIKE "#%"
AND lower(root.name) = 'projects'
AND lower(per.surname) LIKE 'eric%'
OR lower(root.name) = 'clients'
GROUP BY per.surName) AS ticket

ON items.Name = ticket.Name

LEFT JOIN

(SELECT
sum(wi.wEnd-wi.wBegin) AS Total_Hours,
per.surname AS Name
FROM T4U_WORKITEMS wi
INNER JOIN T4U_DAYINFOS di ON ( wi.dayinfo_id = di.id )
INNER JOIN T4U_TASKS t ON ( wi.task_id = t.id )
INNER JOIN T4U_PROJECTS p ON ( wi.project_id = p.id )
INNER JOIN T4U_PERSONS per ON ( di.person_id = per.id )
INNER JOIN T4U_PROJECTS parent ON ( ifnull(p.parent_id , p.id) = parent.id )
INNER JOIN T4U_PROJECTS grandfather ON ( ifnull(parent.parent_id , parent.id) = grandfather.id )
INNER JOIN T4U_PROJECTS great ON ( ifnull(grandfather.parent_id , grandfather.id) = great.id )
INNER JOIN T4U_PROJECTS root ON ( ifnull(great.parent_id , great.id) = root.id )
WHERE di.daydate  BETWEEN '2009-02-10' AND '2009-02-29'
AND lower(root.name) <> 'breaks'
AND lower(per.surname) LIKE 'eric%'
GROUP BY per.surName) AS totaltime

ON items.Name = totaltime.Name

LEFT JOIN

(
SELECT   per.surname AS Name ,
sec_to_time(sum(wi.wEnd-wi.wBegin)) AS Research_Time
FROM T4U_WORKITEMS wi
INNER JOIN T4U_DAYINFOS di ON ( wi.dayinfo_id = di.id )
INNER JOIN T4U_TASKS t ON ( wi.task_id = t.id )
INNER JOIN T4U_PROJECTS p ON ( wi.project_id = p.id )
INNER JOIN T4U_PERSONS per ON ( di.person_id = per.id )
INNER JOIN T4U_PROJECTS parent ON ( ifnull(p.parent_id , p.id) = parent.id )
INNER JOIN T4U_PROJECTS grandfather ON ( ifnull(parent.parent_id , parent.id) = grandfather.id )
INNER JOIN T4U_PROJECTS great ON ( ifnull(grandfather.parent_id , grandfather.id) = great.id )
INNER JOIN T4U_PROJECTS root ON ( ifnull(great.parent_id , great.id) = root.id )
WHERE
di.daydate  BETWEEN '2009-02-10' AND '2009-02-29'
AND lower(root.name) = 'research'
AND lower(per.surname) LIKE 'eric%'
GROUP BY per.surName) AS research

ON research.Name = items.Name

LEFT JOIN

(
SELECT per.surname AS Name ,
sec_to_time(sum(wi.wEnd-wi.wBegin)) AS Others_Time
FROM T4U_WORKITEMS wi
INNER JOIN T4U_DAYINFOS di ON ( wi.dayinfo_id = di.id )
INNER JOIN T4U_TASKS t ON ( wi.task_id = t.id )
INNER JOIN T4U_PROJECTS p ON ( wi.project_id = p.id )
INNER JOIN T4U_PERSONS per ON ( di.person_id = per.id )
INNER JOIN T4U_PROJECTS parent ON ( ifnull(p.parent_id , p.id) = parent.id )
INNER JOIN T4U_PROJECTS grandfather ON ( ifnull(parent.parent_id , parent.id) = grandfather.id )
INNER JOIN T4U_PROJECTS great ON ( ifnull(grandfather.parent_id , grandfather.id) = great.id )
INNER JOIN T4U_PROJECTS root ON ( ifnull(great.parent_id , great.id) = root.id )
WHERE
di.daydate  BETWEEN '2009-02-10' AND '2009-02-29'
AND lower(root.name) <> 'research'
AND lower(root.name) <> 'projects'
AND lower(root.name) <> 'clients'
AND lower(root.name) <> 'breaks'
AND lower(per.surname) LIKE 'eric%'
GROUP BY per.surName) AS others

ON others.Name = items.Name

LEFT JOIN
(
SELECT  per.surname                                  AS Name ,
(max(wi.wEnd)-min(wi.wBegin)
) - sum(wi.wEnd-wi.wBegin) AS un_allocated_time
FROM T4U_WORKITEMS wi
INNER JOIN T4U_DAYINFOS di ON ( wi.dayinfo_id = di.id )
INNER JOIN T4U_TASKS t ON ( wi.task_id = t.id )
INNER JOIN T4U_PROJECTS p ON ( wi.project_id = p.id )
INNER JOIN T4U_PERSONS per ON ( di.person_id = per.id )
INNER JOIN T4U_PROJECTS parent ON ( ifnull(p.parent_id , p.id) = parent.id )

WHERE
di.daydate  BETWEEN '2009-02-10' AND '2009-02-29'
AND per.surName LIKE "eric%"

GROUP BY per.surname )                              AS un_allocated

ON un_allocated.Name = items.Name
分享到:
评论

相关推荐

    generator_for_sqlexample.rar

    后端拿到请求参数需要进行sql语句拼接,由于mybatis-generator的example类存在较多问题,对其进行改进: 1.实现生成的example文件代码量大量减少 2.保证业务代码中不出现sql语句 3.可以生成嵌套的or条件语句 4....

    Winterleaf-WebDavSharp.SQLExample

    Winterleaf-WebDavSharp.SQLExample #A具有权限等的基于SQL Server的Web DAV服务器 !!!!!!!!重要的!!!!!!! 此应用程序仅适用于64位模式。 !!!!!!!!重要的!!!!!!! 对于本软件,我们...

    qt使用sql操作的基础示例

    在本示例中,我们将深入探讨Qt框架下使用SQL进行数据库操作的基本方法。Qt提供了一个强大的接口,使得我们可以轻松地与各种SQL数据库交互,包括SQLite、MySQL、PostgreSQL等。以下将详细介绍标题和描述中提到的四个...

    Oracle PL_SQL by Example 4th.Edition.Aug.2008

    《Oracle PL_SQL by Example》第四版是Oracle数据库开发者的一本权威指南,专注于PL/SQL编程语言的实践应用。这本书在2008年8月发行,以其深入浅出的讲解和丰富的实例,深受广大读者的喜爱。它不仅是初学者的良师,...

    Proc SQL by Example, Using SQL within SAS

    根据提供的文件信息,我们可以深入探讨如何在SAS环境中利用Proc SQL进行数据处理和分析。这份文档似乎是一本关于如何在SAS中运用SQL语言的指南书籍。下面将详细阐述各章节涉及的重要知识点。 ### 一、简介 #### ...

    Oracle PL/SQL by Example(4th Edition)

    《Oracle PL/SQL by Example(4th Edition)》是一本专为Oracle数据库用户设计的PL/SQL编程指南,尤其适合那些希望通过实践学习这一强大的过程式语言的开发者。本书的第四版详细介绍了Oracle PL/SQL的各种核心概念和...

    PL.SQL.By.Example

    《PL.SQL by Example》是一本专注于Oracle数据库PL/SQL编程实践的资源,它提供了一系列的实例脚本,旨在帮助读者深入理解和掌握PL/SQL语言。PL/SQL是Oracle数据库系统中的一个关键组件,用于开发存储过程、触发器、...

    Example_sql示例

    在SQL编程中,`SqlDataReader` 是一个非常重要的类,用于从数据库检索数据并逐行处理。当你执行一个查询命令并尝试使用 `ExecuteReader()` 方法时,它会打开一个到数据库的结果集流,并允许你按需读取数据。然而,...

    Oracle Pl/sql By Example

    Oracle® PL/SQL™ by Example, Third Edition By Benjamin Rosenzweig, Elena Silvestrova Publisher : Prentice Hall PTR Pub Date : September 10, 2003 ISBN : 0-13-117261-1 Pages : 768

    oracle pl/sql by example

    《Oracle PL/SQL by Example》是一本专注于Oracle数据库系统中PL/SQL编程语言的经典教程。PL/SQL,全称为Procedural Language/SQL,是Oracle数据库内置的一种过程化编程语言,它结合了SQL的查询能力与面向过程的编程...

    SQL详细讲解——visuaC#

    namespace SqlExample { class Program { static void Main(string[] args) { string connectionString = "Data Source=(local);Initial Catalog=TestDB;Integrated Security=True"; string query = "SELECT *...

    在SQL2005/2008数据库中调用.NET组件中的函数方法例子程序

    2. 在SQL Server Management Studio(SSMS)中,运行`setup_sqlexample.sql`脚本,将DLL导入并创建所需的数据库对象。 3. 验证.NET组件是否成功注册,可以通过查询sys.assemblies系统视图来检查。 4. 最后,你可以在...

    Oracle SQL By Example 4th Edition by Alice Rischert - 5 Star Book Review.pdf

    Oracle SQL By Example 4th Edition by Alice Rischert - 5 Star Book Review.pdf

    ArcTutor SQL_Example

    【ArcTutor SQL_Example】是一个专门为初学者和专业用户设计的教程,旨在帮助他们理解和掌握如何在GIS(地理信息系统)环境中使用SQL语言操作空间数据库。这个教程是基于ArcGIS平台,由Esri公司开发的ArcTutor系列...

    sql_examples:常用SQL示例和说明的列表

    SQL_EXAMPLES SQL指南 这实际上是常用SQL查询的列表。 最适合在需要刷新或学习查询时用作参考材料。 只需打开文件2 _...,然后使用CTRL + F(或任何可用的搜索)并在查询中搜索关键字。 第一份文档只是SQL的含义,...

    SQL By Example 2017 (epub)

    An introduction to SQL for the absolute beginner. Learn how to create and query databases, add and remove data from tables, set constraints, create stored procedures, and more

    spark SQL学习parquet文件和people.json文件

    spark = SparkSession.builder.appName('Spark SQL Example').getOrCreate() df_parquet = spark.read.parquet('path/to/users.parquet') ``` 这将创建一个DataFrame,可以进一步进行查询和分析。 接下来,我们谈谈...

    Database4 1926079

    支持范例文件管理(SQL Example Manager) 支持拖放数据库加载(DragDrop Database) 结果输出(Export to CSV/XML/TXT) 多国语言显示(Multiple Language): 预设中英文,并可自行扩充 结果打印(Print query ...

Global site tag (gtag.js) - Google Analytics