docID_list = [int(docID_string) for docID_string in os.listdir(document_directory)] docID_list.sort()
时间: 2023-10-25 13:10:22 浏览: 90
这段代码的作用是读取指定目录下的所有文件名,并将文件名转换为整数类型并存储在列表 `docID_list` 中,然后对 `docID_list` 进行排序。
具体来说,这段代码使用 `os.listdir()` 函数获取指定目录 `document_directory` 下的所有文件名,并使用列表推导式将每个文件名转换为整数类型。转换后的整数值表示该文件的文档 ID,可以用于后续的处理。转换后的整数值存储在列表 `docID_list` 中。
然后,使用 `docID_list.sort()` 对 `docID_list` 进行升序排序,确保后续处理中按照文档 ID 的顺序进行。
相关问题
Oracle 下SQL语句怎么写 SELECT @ROWNUM := @ROWNUM + 1 AS TEMPRANK, @INCRNUM := CASE WHEN @ROWTOTAL = OBJ.YLCOUNT + 1 THEN @INCRNUM WHEN @ROWTOTAL := OBJ.YLCOUNT + 1 THEN @ROWNUM END AS FILERANK, OBJ.* FROM ( SELECT DOCINFO.TITLE, DOCINFO.DOC_ID AS DOCID, DOCINFO.DOC_TYPE AS DOCTYPE, U.USER_NAME AS AUTHORNAME, CONCAT( U.USER_NAME, '/', CASE WHEN O.SHORT_NAME = '' THEN '无' ELSE O.SHORT_NAME END ) AS USERNAME, IFNULL( DOCINFO.DOWNLOAD_NUM, 0 ) AS YLCOUNT FROM DOC_INFO DOCINFO, SYS_USERS U, SYS_ORGAN O, sys_stru WHERE DOCINFO.VALID_FLAG = '1' AND IFNULL( DOCINFO.DOWNLOAD_NUM, 0 ) != 0 AND U.USER_ID = DOCINFO.AUTHOR_ID AND sys_stru.STRU_ID = U.DEPARTMENT_ID AND O.ORGAN_ID = sys_stru.ORGAN_ID GROUP BY DOCINFO.DOC_ID, U.USER_NAME ORDER BY DOCINFO.DOWNLOAD_NUM DESC, DOCINFO.TITLE DESC ) OBJ, ( SELECT @ROWNUM := 0, @ROWTOTAL := NULL, @INCRNUM := 0 ) R
在 Oracle 中,可以将该 SQL 语句写成如下形式:
```
SELECT TEMPRANK, FILERANK, TITLE, DOCID, DOCTYPE, AUTHORNAME, USERNAME, YLCOUNT
FROM (
SELECT DOCINFO.TITLE, DOCINFO.DOC_ID AS DOCID, DOCINFO.DOC_TYPE AS DOCTYPE,
U.USER_NAME AS AUTHORNAME, CONCAT(U.USER_NAME, '/', CASE WHEN O.SHORT_NAME = '' THEN '无' ELSE O.SHORT_NAME END) AS USERNAME,
IFNULL(DOCINFO.DOWNLOAD_NUM, 0) AS YLCOUNT,
@ROWNUM := @ROWNUM + 1 AS TEMPRANK,
@INCRNUM := CASE
WHEN @ROWTOTAL = OBJ.YLCOUNT + 1 THEN @INCRNUM
WHEN @ROWTOTAL := OBJ.YLCOUNT + 1 THEN @ROWNUM
END AS FILERANK
FROM DOC_INFO DOCINFO, SYS_USERS U, SYS_ORGAN O, sys_stru
WHERE DOCINFO.VALID_FLAG = '1'
AND IFNULL(DOCINFO.DOWNLOAD_NUM, 0) != 0
AND U.USER_ID = DOCINFO.AUTHOR_ID
AND sys_stru.STRU_ID = U.DEPARTMENT_ID
AND O.ORGAN_ID = sys_stru.ORGAN_ID
GROUP BY DOCINFO.DOC_ID, U.USER_NAME
ORDER BY DOCINFO.DOWNLOAD_NUM DESC, DOCINFO.TITLE DESC
) OBJ, (SELECT @ROWNUM := 0, @ROWTOTAL := NULL, @INCRNUM := 0) R;
```
在 Oracle 中,变量需要在 SQL 语句外面进行声明和初始化。这里使用了 `@ROWNUM`、`@ROWTOTAL` 和 `@INCRNUM` 三个变量,它们都在 SQL 语句的最后一行进行了声明和初始化。
此外,由于 Oracle 对于 SQL 语句的执行顺序与 MySQL 略有不同,因此需要将临时变量的计算放在子查询中,并使用外层查询来获取这些变量的值。最终的结果集是从子查询中返回的。
select * from docimagefile where imagefileid in(select b.imagefileid from (select max(imagefileid) as imagefileid,docid from docimagefile where (isextfile is null or isextfile='') and docid in(select docid from odoc_requestdoc) and docfiletype in(3,7) group by docid)a left join docimagefile b on a.docid=b.docid where b.imagefileid<a.imagefileid) 改为只查docid为749的数据
你的问题是如何将这个 SQL 查询改为只查 `docid` 为 749 的数据。那么可以将原来内查询中的 `docid` 条件改为 `749`,如下所示:
```
select * from docimagefile
where imagefileid in(
select b.imagefileid
from (
select max(imagefileid) as imagefileid, docid
from docimagefile
where (isextfile is null or isextfile='')
and docid = 749 -- 修改点在此
and docfiletype in(3,7)
group by docid
) a
left join docimagefile b on a.docid=b.docid
where b.imagefileid<a.imagefileid
)
```
这样就只会查询 `docid` 为 749 的数据了。
阅读全文