sql 中易犯错:用别名作为筛选条件
来源:互联网 发布:木工设计软件手机 编辑:程序博客网 时间:2024/05/22 17:31
如 错误代码:
select ii.id as 投资编号,
ii.PROTOCOL_NO as 合同编号,
'F' || CR_CUSTOMER_NUMBER || '-' || ii.LENDING_No as 出借编号,
cu.cr_name as 客户姓名,ii.loan_return_date,
(case ii.loan_return_date
when '00120001' then
'1日'
else
'16日'
end) as loan_retunedate,
(case ii.regular_type
when '00130001' then
trim('.' from to_char(ii.invest_amt, 'FM999,999,999.99'))
else
trim('.' from to_char(ii.Regular_Amt, 'FM999,999,999.99'))
end) as amt,
to_char(ii.agreed_delivery_date, 'yyyy-MM-dd'),
td.data_name,
wf.node_name,
(case ii.regular_type
when '00130001' then
to_char(ii.invest_start_date, 'yyyy-MM-dd')
else
to_char(ii.regular_start_date, 'yyyy-MM-dd')
end) as end_date,
to_char(ii.create_date, 'yyyy-MM-dd')
from ft_t_invest_info ii
left join crmFT.crm_customer@To_Crm cu
on ii.customer_id = cu.id
left join sys_t_dictionary td
on ii.product_type = td.data_code
left join ft_t_flow_def wf
on wf.node_code = ii.flow_id
where cu.cr_customer_number not in (1, 2, 3, 4)
and loan_return_date ='1日'
错误1:用别名作为筛选条件
错误2:‘1日’是结果集后显示,结果集不包含‘1日’,包含‘0012000’
正确一 sql:
select ii.id as 投资编号,
ii.PROTOCOL_NO as 合同编号,
'F' || CR_CUSTOMER_NUMBER || '-' || ii.LENDING_No as 出借编号,
cu.cr_name as 客户姓名,ii.loan_return_date,
(case ii.loan_return_date
when '00120001' then
'1日'
else
'16日'
end) as loan_retunedate,
(case ii.regular_type
when '00130001' then
trim('.' from to_char(ii.invest_amt, 'FM999,999,999.99'))
else
trim('.' from to_char(ii.Regular_Amt, 'FM999,999,999.99'))
end) as amt,
to_char(ii.agreed_delivery_date, 'yyyy-MM-dd'),
td.data_name,
wf.node_name,
(case ii.regular_type
when '00130001' then
to_char(ii.invest_start_date, 'yyyy-MM-dd')
else
to_char(ii.regular_start_date, 'yyyy-MM-dd')
end) as end_date,
to_char(ii.create_date, 'yyyy-MM-dd')
from ft_t_invest_info ii
left join crmFT.crm_customer@To_Crm cu
on ii.customer_id = cu.id
left join sys_t_dictionary td
on ii.product_type = td.data_code
left join ft_t_flow_def wf
on wf.node_code = ii.flow_id
where cu.cr_customer_number not in (1, 2, 3, 4)
and ii.loan_return_date ='00120001'
正确二 sql:
select * from (select ii.id as 投资编号,
ii.PROTOCOL_NO as 合同编号,
'F' || CR_CUSTOMER_NUMBER || '-' || ii.LENDING_No as 出借编号,
cu.cr_name as 客户姓名,ii.loan_return_date,
(case ii.loan_return_date
when '00120001' then
'1日'
else
'16日'
end) as loan_retunedate,
(case ii.regular_type
when '00130001' then
trim('.' from to_char(ii.invest_amt, 'FM999,999,999.99'))
else
trim('.' from to_char(ii.Regular_Amt, 'FM999,999,999.99'))
end) as amt,
to_char(ii.agreed_delivery_date, 'yyyy-MM-dd'),
td.data_name,
wf.node_name,
(case ii.regular_type
when '00130001' then
to_char(ii.invest_start_date, 'yyyy-MM-dd')
else
to_char(ii.regular_start_date, 'yyyy-MM-dd')
end) as end_date,
to_char(ii.create_date, 'yyyy-MM-dd')
from ft_t_invest_info ii
left join crmFT.crm_customer@To_Crm cu
on ii.customer_id = cu.id
left join sys_t_dictionary td
on ii.product_type = td.data_code
left join ft_t_flow_def wf
on wf.node_code = ii.flow_id
where loan_retunedate='1日'
- sql 中易犯错:用别名作为筛选条件
- SQL语句Where中使用别名作为判断条件
- SQL语句Where中使用别名作为判断条件
- SQL语句Where中使用别名作为判断条件
- Oracle中时间字段作为筛选条件
- combox值作为筛选条件
- sybase的sql字段别名,可以直接作为where中的条件
- Code First Entity Framework动态组合Lambda表达式作为数据筛选条件,代替拼接SQL语句
- Code First Entity Framework动态组合Lambda表达式作为数据筛选条件,代替拼接SQL语句
- 自定义Lamda表达式作为筛选条件
- oracle中表中含有的日期字段如何作为筛选条件
- SQL中text字段如何作为判断条件
- SQL 截取日期作为条件
- SQL拼接一个满足条件筛选后的字段到一个虚拟字段中
- sql中别名的用处
- landa中角色的筛选条件
- 平台中多条件筛选功能
- 条件筛选
- ORA-01078 ORA-01565 ORA-17503 ORA-15056 ORA-17503 ORA-15001 ORA-06512
- Hbase 的 官方指令介绍
- goldengate ERROR OGG-01161 Bad column index (21)
- java 几种远程服务调用协议的比较
- 让软件测试团队慢慢死去
- sql 中易犯错:用别名作为筛选条件
- 程序局部性原理
- 如何成为一名优秀的web前端工程师(前端攻城师)
- mysql报错
- IE中输入框无法输入问题
- Linux串口编程(中断方式和select方式)
- 二叉查找树综述
- struts静态动态ActionForm使用(二)—验证
- 浅析检查email的正则表达式