Derby数据库下有三张表:
CS_ESI_EMAIL_CONFIGWHERE(用户注册表)1834条记录
CS_ESI_EMAIL_LOG(邮件id和用户名)61301条记录,包括时间段2012-02-01到2012-05-14
CS_ESI_EMAIL_LOG_BAK120305(邮件id和用户名)78735条记录,包括时间段2011-10-01到2012-03-05
要求找出2012-01-01到2012-07-01期间没有邮件的用户
我的解决方法如下:
CREATE VIEW TESTV ASSELECT EMAIL_CONFIG_UUID,MAILBOX_NAME,C
S_USER_ID,STATUS FROM CS_ESI_EMAIL_CONFIGWHERE EMAIL_CONFIG_UUID NOT IN(SELECT
EMAIL_CONFIG_UUID FROM CS_ESI_EMAIL_LOG WHERE RECEIVED_DT >'2012-02-01' AND REC
EIVED_DT <= '2012-07-01' UNION SELECTEMAIL_CONFIG_UUID FROM CS_ESI_EMAIL_LOG_BA
K120305 WHERE RECEIVED_DT >='2012-01-01' AND RECEIVED_DT <= '2012-02-01');
SELECTEMAIL_CONFIG_UUID,MAILBOX_NAME FROM(SELECT ROW_NUMBER() OVER() AS row
num, TESTV.* FROM TESTV) AS TMP WHEREROWNUM <= 50 AND ROWNUM >= 0;
由于上面的查询语句查了一个多钟头都查不出来,后来我把上面的蓝色部分抽取出来,放到一个表里面,然后在建立视图view的时候用表代替那段查询语句,变成了下面的代码,结果几秒钟就查出来了(查出801条数据),原因应该是如果直接嵌入的话需要拆开做很多的and和判断操作
CREATE TABLE TESTTABLE(EMAIL_CONFIG_UUID INTEGER PRIMARY KEY);
WHERE RECEIVED_DT > '2012-02-01' AND RECEIVED_DT <= '2012-07-01'UNION
SELECT EMAIL_CONFIG_UUID FROM CS_ESI_EMAIL_LOG_BAK120305 WHERE RECEIVED_DT >=
'2012-01-01' AND RECEIVED_DT <= '2012-02-01';
TESTV.* FROM TESTV) AS TMP WHERE ROWNUM <= 100 AND ROWNUM >= 0;
遗留问题:
1、Derby中是否不能用create table as select语句创建表,老是报Encountered <EOF> 异常
2、Derby中是否没有全外联结full outer join
3、我有些查询字段有创建了索引,有帮助的吗?