gpt4 book ai didi

sql - 添加列以查看

转载 作者:行者123 更新时间:2023-11-29 13:05:47 30 4
gpt4 key购买 nike

我在 Adempiere 工作,现在在 pgAdmin III 中使用来自 adempiere 的数据库。我得到了这段代码,我刚刚学习 SQL 3 天。

所以我有这段代码:

SELECT t.m_transaction_id, t.ad_client_id, t.ad_org_id, t.movementtype, 
t.movementdate, t.movementqty, t.m_attributesetinstance_id,
asi.m_attributeset_id, asi.serno, asi.lot, asi.m_lot_id, asi.guaranteedate,
t.m_product_id, p.value, p.name, p.description, p.upc, p.sku, p.c_uom_id,
p.m_product_category_id, p.classification, p.weight, p.volume, p.versionno,
t.m_locator_id, l.m_warehouse_id, l.x, l.y, l.z, t.m_inventoryline_id,
il.m_inventory_id, t.m_movementline_id, ml.m_movement_id, t.m_inoutline_id,
iol.m_inout_id, t.m_productionline_id, prdl.m_productionplan_id, prdp.m_production_id,
t.c_projectissue_id, pjl.c_project_id,
COALESCE(il.line, ml.line, iol.line, prdl.line, pjl.line)
AS line,
daysbetween(
(T .movementdate):: TIMESTAMP WITH TIME ZONE,
getdate()
)AS movementagedays

FROM adempiere.m_transaction t
JOIN adempiere.m_locator l ON t.m_locator_id = l.m_locator_id
JOIN adempiere.m_product p ON t.m_product_id = p.m_product_id
LEFT JOIN adempiere.m_attributesetinstance asi ON t.m_attributesetinstance_id =
asi.m_attributesetinstance_id
LEFT JOIN adempiere.m_inventoryline il ON t.m_inventoryline_id = il.m_inventoryline_id
LEFT JOIN adempiere.m_movementline ml ON t.m_movementline_id = ml.m_movementline_id
LEFT JOIN adempiere.m_inoutline iol ON t.m_inoutline_id = iol.m_inoutline_id
LEFT JOIN adempiere.m_productionline prdl ON t.m_productionline_id =
prdl.m_productionline_id
LEFT JOIN adempiere.m_productionplan prdp ON prdl.m_productionplan_id =
prdp.m_productionplan_id
LEFT JOIN adempiere.c_projectissue pjl ON t.c_projectissue_id = pjl.c_projectissue_id;

以漂亮的表格结尾(查看 rv_transaction):

table http://imageshack.us/a/img829/3558/tablerl.png

最后一列是 movementagedays,它告诉我们有多少天没有对产品进行操作。

我只想添加一列“islager”,如果 movementagedays 列中相应行的值小于 -90,该列将以“超过 90 天”结尾。

所以我写了类似的东西

CASE WHEN movementagedays < -90 THEN 'more than 90 days' 
END AS isLager
FROM rv_transaction

但我不知道它是否正确以及应该把它放在哪里另外,如果大代码写得好,性能优化等,我会知道。

如果有人能帮助我,我会很高兴。对不起,我的 SQL 技能和英语都不好

最佳答案

几乎是对的。对你来说正确的陈述应该是:

SELECT *,
CASE WHEN movementagedays < -90
THEN 'more than 90 days'
ELSE NULL END AS isLager
FROM rv_transaction

关于sql - 添加列以查看,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13063395/

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