我们说我有一张表:
CREATE TABLE tbl_TableFullOfStuff (id INTEGER, Name STRING, date1 INTEGER, date2 INTEGER);
有东西:
INSERT INTO tbl_TableFullOfStuff VALUES(1,"thing one", 1448486601, 1448486602); INSERT INTO tbl_TableFullOfStuff VALUES(2,"thing two", 1448486605, 1448486606); INSERT INTO tbl_TableFullOfStuff VALUES(3,"thing three", 1448486603, 1448486604);
如何创建一个为每个时间戳创建独立行的视图?
NAME |TIMESTAMP thing one |1448486601 thing one |1448486602 thing three |1448486603 thing three |1448486604 thing two |1448486605 thing two |1448486606
答案 0 :(得分:1)
您可以使用UNION ALL
:
CREATE VIEW my_view
AS
SELECT name, date1 AS TIMESTAMP
FROM tbl_TableFullOfStuff
UNION ALL
SELECT name, date2 AS TIMESTAMP
FROM tbl_TableFullOfStuff;
SELECT *
FROM my_view
ORDER BY name, TIMESTAMP;
的 SQLFiddleDemo
强>