sql语句总结

1、优秀sql语句:

SELECT
r.refund_code 退单编号,
r.order_code 订单编号,
g.product_full_name_cn 商品名称,
g.product_variant_code 商品编码,
CASE
WHEN length( g.product_variant_code ) = 7 THEN
'饰品' ELSE '手表'
END '商品类别',
CASE WHEN r.refund_type = 'REFUND' THEN '发货前'
WHEN r.refund_type ='RETURNS&REFUNDS' THEN '发货后'
END '退单类别',
-- r.refund_type = CASE 'REFUND' WHEN 'REFUND' THEN '发货前'
-- WHEN 'RETURNS&REFUNDS' THEN '发货后'
-- END '退单类别',
r.created_time 退货时间,
g.pay_price 退单金额,
g.quantity 退单数量,
CASE

WHEN r.refund_status = 'REFUND_SUCCESS' THEN
'退单成功'
END '退单状态',
r.created_time 退货时间
FROM
official_website.refund_main r
JOIN official_website.refund_goods g ON r.refund_code = g.refund_code
WHERE
-- refund_type = case '{1}' when '发货前' then 'REFUND' when '发货后' THEN 'RETURNS&REFUNDS'
-- end
refund_type = case '发货前' when '发货前' then 'REFUND' when '发货后' THEN 'RETURNS&REFUNDS'
end
-- refund_type = 'REFUND'
AND is_deleted = 0
AND if ('手表'='饰品', LENGTH( g.product_variant_code )!=7,LENGTH( g.product_variant_code )=7)
-- AND LENGTH( g.product_variant_code ) = 7
AND date(r.created_time) >= '2022-02-01 00:00:00'
AND date(r.created_time) <= '2022-02-28 23:59:59'
AND r.refund_status = 'REFUND_SUCCESS';

posted @ 2023-01-13 09:42  奈何技术不达标  阅读(36)  评论(0编辑  收藏  举报