-
sql 条件查询case when5
select *
from (case when(t1.bxdw = t2.bxdw) then
select t1.bxdw bxdw,
(t1.zje - t2.zje) pk,
t1.tpfy tpfy,
(t1.yx - t2.tpsm) yx,
t2.tpsm tpsm,
(t1.zje - t2.zje + t1.tpfy) zje else
select t1.bxdw bxdw,
t1.zje pk,
t1.tpfy tpfy,
t1.yx yx,
(t1.yx - t1.yx) tpsm,
(t1.zje + t1.tpfy) zje end
from (select bxdw,
sum(zjje) zje,
count(*) yx,
sum(tpfy) tpfy
from CWXT_JPDG_B_YDXX
group by bxdw) t1,
(select bxdw, sum(zjje) zje, count(*) tpsm
from CWXT_JPDG_B_YDXX
where sftp = 1
group by bxdw) t2
)
在when条件哪里报缺失右括号的错误 请问错误是什么 怎样改正2014年12月15日 12:55
1个答案 按时间排序 按投票排序
-
采纳的答案
case when不是这么用的。。
列
SELECT (case when cl.colno=cc.colno then cl.cola||cc.colb else cl.colb||cc.colc end) as testa,
(case when cl.colno=cc.colno then cl.sortno||cc.colc else cl.colf||cc.colg end) as testb FROM tabcl cl,tabcc cc
按你的sql大概可以改成这样
select t1.bxdw,(case when t1.bxdw = t2.bxdw then (t1.zje - t2.zje) then t1.zje end) as pk,t1.tpfy,
(case when t1.bxdw = t2.bxdw then (t1.yx - t2.tpsm) else t1.yx end) as yx,
(case when t1.bxdw = t2.bxdw then t2.tpsm else (t1.yx - t1.yx) end) as tpsm,
(case when t1.bxdw = t2.bxdw then (t1.zje - t2.zje + t1.tpfy) else (t1.zje + t1.tpfy) end) as zje from ......
没有办法测试,你自己测一下。2014年12月16日 10:45
相关推荐
1 case when 写法 2 sum case when 用法 3 select 拼接字段 示例如下: when 2 then 'C' else 'D' end ) as '类型',count(*) as '数量' from table group by orderType
sql数据库 转 Access SQL语句改写之 Case When Then When Then Else End!值得下载看看!资源免费,大家分享!! 更多免费资源 http://ynsky.download.csdn.net/
sql 存储过程 常见的问题 自己用也可分享
SQL__case_when_then_的用法
主要介绍了SqlServer使用 case when 解决多条件模糊查询问题 的相关资料,需要的朋友可以参考下
一条sql语句就能让你case when then怎么用,什么时候用
SQL学习六-CASE WHEN
CASE 可能是 SQL 中被误用最多的关键字之一。虽然你可能以前用过这个关键字来创建字段,但是它还具有更多用法。例如,你可以在 WHERE 子句中使用 CASE。本文将为大家介绍SQL Server中Case 的不同用法。
sql学习 催人泪下-CASE WHEN改造.sql
本文档介绍了SQL中case...when的用法。
NULL 博文链接:https://576017120.iteye.com/blog/1624774
mysql 中case when 遇到乱码解决。查询语句中含有case引起中文乱码解决方法
主要介绍了sql学习之CASE WHEN THEN ELSE END的用法,需要的朋友可以参考下
Sql_Case_When用法用例[参考].pdf
模型快速部署之决策树模型转SQL-case-when概率代码
as 月份 CASE 可能是 SQL 中被误用最多的关键字之一。虽然你可能以前用过这个关键字来创建字段,但是它还具有更多用法。例如,你可以在 WHERE 子句中使用 CASE。 首先让我们看一下 CASE 的语法。在一般的 SELEC
sql 联合查询 子查询 综合查询 统计数据 case when then 用法