Oracle使用表中的特定记录创建视图

时间:2017-11-07 07:45:48

标签: sql oracle view

我想从下表创建一个名为TB_STATUS的视图。

ID  EVENT_DATE       REOPEN_DATE
4   15/1/2013 0:00  
5   16/1/2013 16:36  16/1/2013 0:00
2   16/1/2013 16:38 
6   16/1/2013 17:12  16/1/2013 0:00
11  4/8/2013 11:00  
7   4/1/2014 9:00    4/1/2014 0:00
9   4/1/2014 11:00  
8   5/1/2014 14:00   5/1/2014 0:00

预期视图内容在REOPEN_DATE之间为keytool -import -alias alias_name -file cer_name.cer -storepass changeit -keystore my_keystore.keystore ,如下所示:

Error:Execution failed for task ':packageDebug'.
> com.android.ide.common.signing.KeytoolException: Failed to read key alias_name from store "C:\Users\username\my_keystore.keystore": trusted certificate entries are not password-protected

上述数据集的预期结果如下:

keytool -import -alias alias_name -file cer_name.cer -storepass changeit -keypass changeit -keystore my_keystore.keystore

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

SQL Fiddle

Oracle 11g R2架构设置

CREATE TABLE TB_STATUS(
  ID          INTEGER PRIMARY KEY,
  EVENT_DATE  DATE NOT NULL,
  REOPEN_DATE DATE
);

INSERT INTO TB_STATUS
SELECT  1, TIMESTAMP '2013-01-16 16:16:00', NULL FROM DUAL UNION ALL
SELECT  2, TIMESTAMP '2013-01-16 16:38:00', NULL FROM DUAL UNION ALL
SELECT  3, TIMESTAMP '2013-01-16 18:18:00', NULL FROM DUAL UNION ALL
SELECT  4, TIMESTAMP '2013-01-15 00:00:00', NULL FROM DUAL UNION ALL
SELECT  5, TIMESTAMP '2013-01-16 16:36:00', TIMESTAMP '2013-01-16 00:00:00' FROM DUAL UNION ALL
SELECT  6, TIMESTAMP '2013-01-16 17:12:00', TIMESTAMP '2013-01-16 00:00:00' FROM DUAL UNION ALL
SELECT  7, TIMESTAMP '2014-01-04 09:00:00', TIMESTAMP '2014-01-04 00:00:00' FROM DUAL UNION ALL
SELECT  8, TIMESTAMP '2014-01-05 14:00:00', TIMESTAMP '2014-01-05 00:00:00' FROM DUAL UNION ALL
SELECT  9, TIMESTAMP '2014-01-04 11:00:00', NULL FROM DUAL UNION ALL
SELECT 10, TIMESTAMP '2014-01-04 16:00:00', NULL FROM DUAL UNION ALL
SELECT 11, TIMESTAMP '2013-08-04 11:00:00', NULL FROM DUAL UNION ALL 
SELECT 12, TIMESTAMP '2013-08-15 01:00:00', NULL FROM DUAL;

CREATE VIEW TB_STATUS_MINS AS
SELECT ID,
       EVENT_DATE, -- CASE WHEN REOPEN_DATE IS NULL THEN EVENT_DATE END,
       REOPEN_DATE
FROM   (
  SELECT t.*,
         LAG( REOPEN_DATE, 1, DATE '1970-01-01' ) OVER ( ORDER BY EVENT_DATE ) AS prev_reopen
  FROM   TB_STATUS t
)
WHERE  reopen_date IS NOT NULL
OR     prev_reopen IS NOT NULL

查询1

SELECT *
FROM   TB_STATUS_MINS

<强> Results

| ID |           EVENT_DATE |          REOPEN_DATE |
|----|----------------------|----------------------|
|  4 | 2013-01-15T00:00:00Z |               (null) |
|  5 | 2013-01-16T16:36:00Z | 2013-01-16T00:00:00Z |
|  2 | 2013-01-16T16:38:00Z |               (null) |
|  6 | 2013-01-16T17:12:00Z | 2013-01-16T00:00:00Z |
|  3 | 2013-01-16T18:18:00Z |               (null) |
|  7 | 2014-01-04T09:00:00Z | 2014-01-04T00:00:00Z |
|  9 | 2014-01-04T11:00:00Z |               (null) |
|  8 | 2014-01-05T14:00:00Z | 2014-01-05T00:00:00Z |