我有如下表格。如果我需要创建另一个表,如输出中所示,我该怎么办?
CREATE TABLE TestTable
(JobID int, isAllowType1 bit, value1 int, isAllowType2 bit, value2 int)
;
INSERT INTO TestTable
(JobID, isAllowType1, value1, isAllowType2, value2)
VALUES
(1, 1, 11, 0, 111),
(2, 0, 22, 1, 222),
(3, 1, 33, 0, 333)
;
- 输出
JOBID isAllow Value Type
1 1 11 Type1
1 0 111 Type2
2 0 22 Type1
2 1 222 Type2
3 1 33 Type1
3 0 333 Type2
答案 0 :(得分:2)
您可以单独使用查询type1和type2记录,并使用union all
运算符组合结果:
SELECT jobid, isAllowType1 AS isAllow, value1 AS value, 'Type1' AS type
FROM testtable
UNION ALL
SELECT jobid, isAllowType1 AS isAllow, value1 AS value, 'Type2' AS type
FROM testtable
答案 1 :(得分:0)
要添加到Mureinik的答案,您可以使用<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p class="toggleMe">
Some text!
</p>
<button type="button">
Click Me!
</button>
的结果创建一个新表格,如下所示:
UNION ALL