注册 登录
编程论坛 SQL Server论坛

一个SQL语法问题

wube 发布于 2018-12-19 15:46, 2369 次点击
有一段查询数据库语法

1.  Select A.ProjectNo, D.CateMainName,D.CateSubName ,B.ItemNo,B.ItemName,C.CreateDate,C.CreatorNo,C.DHRemark
    FROM tblProject As A
    INNER JOIN tblProjectItem As B On A.ProjectNo=B.ProjectNo
    INNER JOIN tblProjectDevpHistory As C On B.ProjectNo=C.ProjectNo And B.ItemNo=C.ItemNo
    INNER JOIN tblBasCategory As D On A.CateMainID=D.CateMainID and A.CateSubID=D.CateSubID
    Where C.CreateDate>'2018-12-16' and C.CreateDate<'2018-12-22' order by A.CateMainID

    这样写会变成以下表栏位 :
    ProjectNo CateMainName CateSubName ItemNo ItemName CreateDate    CreatorNo    DHRemark

2. 1怎么结合COUNT(*)变成下方表栏位?

    No. ProjectNo CateMainName CateSubName ItemNo ItemName CreateDate    CreatorNo    DHRemark
2 回复
#2
wube2018-12-19 20:36
    Select ROW_NUMBER() OVER (ORDER BY A.CateMainID) AS RowNo, A.ProjectNo, D.CateMainName,D.CateSubName ,B.ItemNo,B.ItemName,C.CreateDate,C.CreatorNo,C.DHRemark
    FROM tblProject As A
    INNER JOIN tblProjectItem As B On A.ProjectNo=B.ProjectNo
    INNER JOIN tblProjectDevpHistory As C On B.ProjectNo=C.ProjectNo And B.ItemNo=C.ItemNo
    INNER JOIN tblBasCategory As D On A.CateMainID=D.CateMainID and A.CateSubID=D.CateSubID
    Where C.CreateDate>'2018-12-16' and C.CreateDate<'2018-12-22'

试出来了,自问自答。

[此贴子已经被作者于2018-12-19 20:37编辑过]

#3
sssooosss2020-07-30 08:34
自学印象深刻
1