M
MingWord
Unregistered / Unconfirmed
GUEST, unregistred user!
下面这一条SQL语句
SELECT dbo.TIndex.Attribute, dbo.TIndex.Num,ISNULL(T.NUMCOUNT,0)AS NUMCOUNT
FROM dbo.TtmpType INNER JOIN
dbo.TIssue ON dbo.TtmpType.TypeID = dbo.TIssue.typeid INNER JOIN
dbo.TNum ON dbo.TIssue.IssueID = dbo.TNum.IssueID INNER JOIN
dbo.TIndex ON dbo.TNum.IndexId = dbo.TIndex.IndexID AND dbo.TtmpType.TypeID = dbo.TIndex.Typeid
LEFT JOIN(
SELECT dbo.TIndex.Attribute, dbo.TIndex.Num,COUNT(dbo.TIndex.Num)AS NUMCOUNT
FROM dbo.TtmpType INNER JOIN
dbo.TIssue ON dbo.TtmpType.TypeID = dbo.TIssue.typeid INNER JOIN
dbo.TNum ON dbo.TIssue.IssueID = dbo.TNum.IssueID INNER JOIN
dbo.TIndex ON dbo.TNum.IndexId = dbo.TIndex.IndexID AND dbo.TtmpType.TypeID = dbo.TIndex.Typeid
WHERE dbo.TIndex.Attribute = 0 AND TIssue.Series BETWEEN 700 AND 704
GROUP BY dbo.TIndex.Attribute,dbo.TIndex.Num)T ON dbo.TIndex.Num = T.NUM
WHERE dbo.TIndex.Attribute = 0 AND TIssue.Series=705
查出的结果为
attribute num numcount
0 13 3
0 20 0
0 10 2
0 34 2
0 30 1
0 18 0
0 21 1
但我希望得到的结果是
SERIES PART0 PART0STR PART1 PART1STR PART2 PART2STR OTHERPART OTHERPARTSTR
705 | 2 | 18 20 | 2 | 21 30 | 2 | 10 34 | 1 | 13 |
SELECT dbo.TIndex.Attribute, dbo.TIndex.Num,ISNULL(T.NUMCOUNT,0)AS NUMCOUNT
FROM dbo.TtmpType INNER JOIN
dbo.TIssue ON dbo.TtmpType.TypeID = dbo.TIssue.typeid INNER JOIN
dbo.TNum ON dbo.TIssue.IssueID = dbo.TNum.IssueID INNER JOIN
dbo.TIndex ON dbo.TNum.IndexId = dbo.TIndex.IndexID AND dbo.TtmpType.TypeID = dbo.TIndex.Typeid
LEFT JOIN(
SELECT dbo.TIndex.Attribute, dbo.TIndex.Num,COUNT(dbo.TIndex.Num)AS NUMCOUNT
FROM dbo.TtmpType INNER JOIN
dbo.TIssue ON dbo.TtmpType.TypeID = dbo.TIssue.typeid INNER JOIN
dbo.TNum ON dbo.TIssue.IssueID = dbo.TNum.IssueID INNER JOIN
dbo.TIndex ON dbo.TNum.IndexId = dbo.TIndex.IndexID AND dbo.TtmpType.TypeID = dbo.TIndex.Typeid
WHERE dbo.TIndex.Attribute = 0 AND TIssue.Series BETWEEN 700 AND 704
GROUP BY dbo.TIndex.Attribute,dbo.TIndex.Num)T ON dbo.TIndex.Num = T.NUM
WHERE dbo.TIndex.Attribute = 0 AND TIssue.Series=705
查出的结果为
attribute num numcount
0 13 3
0 20 0
0 10 2
0 34 2
0 30 1
0 18 0
0 21 1
但我希望得到的结果是
SERIES PART0 PART0STR PART1 PART1STR PART2 PART2STR OTHERPART OTHERPARTSTR
705 | 2 | 18 20 | 2 | 21 30 | 2 | 10 34 | 1 | 13 |