gpt4 book ai didi

sql - 将 SQL 查询中的值除以 1024 以获得以 KB 为单位的大小

转载 作者:行者123 更新时间:2023-12-02 08:27:46 26 4
gpt4 key购买 nike

我按照以下查询提取字节大小:

 SELECT CASE_NUM, 
CUST_CODE,
CUST_NAME,
ISNULL(C.[NR OF ATTACHMENTS], 0) 'NR OF ATTACHMENTS',
ISNULL(C.[SIZE OF ATTACHMENTS KB], 0) 'SIZE OF ATTACHMENTS KB'
FROM CUSTCASE
LEFT OUTER JOIN (
SELECT B.CASE_CODE,
ISNULL(COUNT(B.ATTACHED_DOC_ID), 0) 'NR OF ATTACHMENTS',
ISNULL(SUM(B.DOC_SIZE), 0) 'SIZE OF ATTACHMENTS KB'
FROM
(SELECT CASE_CODE,
ATTACHED_DOC_ID,
ISNULL(A.DOC_SIZE, 0) 'DOC_SIZE'
FROM CONTACT
LEFT OUTER JOIN (SELECT DOC_ID,
DATALENGTH(DATA) 'DOC_SIZE'
FROM ATTACHED_DOCS) A
ON CONTACT.ATTACHED_DOC_ID = A.DOC_ID
WHERE CONTACT.CASE_CODE IS NOT NULL) B
GROUP BY B.CASE_CODE
) C
ON CUSTCASE.CASE_CODE = C.CASE_CODE
where ISNULL(C.[NR OF ATTACHMENTS], 0) > 0

要获得 KB 的大小,我需要除以 1024 但无法在这种情况下应用它。

最佳答案

SELECT CASE_NUM, CUST_CODE, CUST_NAME, ISNULL(C.[NR OF ATTACHMENTS], 0) 'NR OF ATTACHMENTS', CASE WHEN ISNULL(C.[SIZE OF ATTACHMENTS KB], 0) = 0 THEN 0 ELSE C.[SIZE OF ATTACHMENTS KB]/1024) END AS 'SIZE OF ATTACHMENTS KB' 
FROM CUSTCASE
LEFT OUTER JOIN (SELECT B.CASE_CODE, ISNULL(COUNT(B.ATTACHED_DOC_ID), 0) 'NR OF ATTACHMENTS', CASE WHEN ISNULL(SUM(B.DOC_SIZE), 0) = 0 THEN 0 ELSE SUM(B.DOC_SIZE)/1024 END AS 'SIZE OF ATTACHMENTS KB'
FROM (SELECT CASE_CODE, ATTACHED_DOC_ID, ISNULL(A.DOC_SIZE, 0) 'DOC_SIZE'
FROM CONTACT
LEFT OUTER JOIN (SELECT DOC_ID, DATALENGTH(DATA) 'DOC_SIZE'
FROM ATTACHED_DOCS) A ON CONTACT.ATTACHED_DOC_ID = A.DOC_ID
WHERE CONTACT.CASE_CODE IS NOT NULL) B
GROUP BY B.CASE_CODE) C ON CUSTCASE.CASE_CODE = C.CASE_CODE
WHERE ISNULL(C.[NR OF ATTACHMENTS], 0) > 0

关于sql - 将 SQL 查询中的值除以 1024 以获得以 KB 为单位的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30502539/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com