SQL语句的写法:Update、Case、 Select 一起的用法
来源:互联网 发布:三星windows phone 编辑:程序博客网 时间:2024/04/29 19:44
修改数据,需要验证后修改对应的数据,而验证的字段不再修改表中,就需要对多表进行查询,花了些时间想出了如下办法,感觉还是挺有用的,也挺过瘾的,之前很少碰到这样的,所以再次记录下:
(此业务逻辑没有详细说明,如果你正在看这些,只需要看SQL的写的语法,相信您能看懂,也希望对您有所帮助)
-------------------------------------------Update 与 Select 一起的用法--Update 通过多表来修改数据-------------------------------------------参考写法1:update B1 set strNum = strNum - B2.intNumwhere strId in (select intId from B2 where B2.intId = B1.strId)--参考写法2:update B1 set strNum = strNum - B2.intNumfrom B1 inner join B2on B2.intId = B1.strIdselect * from pro_res_assign,pro_gantt_taskwhere pro_res_assign.task_id = pro_gantt_task.task_idand pro_res_assign.resource_id = 'jxstar4918'update pro_gantt_task set pro_gantt_task.responsible_id = pro_res_assign.user_id ,pro_gantt_task.responsible = pro_res_assign.res_namefrom pro_res_assign,pro_gantt_taskwhere pro_res_assign.task_id = pro_gantt_task.task_idand pro_res_assign.resource_id = 'jxstar4918'--------------------------------最终完成的SQL------------------------------update pro_gantt_task set pro_gantt_task.responsible_id = (case when pro_res_assign.responsible_type = '1' then pro_res_assign.user_id else null end),pro_gantt_task.responsible = (case when pro_res_assign.responsible_type = '1' then pro_res_assign.res_name else null end)from pro_res_assign,pro_gantt_taskwhere pro_res_assign.task_id = pro_gantt_task.task_idand pro_res_assign.resource_id = 'jxstar4918'--测试查询select res_type,user_id,res_name,task_id from pro_res_assign where resource_id = 'jxstar4918'select responsible_id,responsible from pro_gantt_task以下是WBS计划反写备份:--select user_id,res_name,task_id from pro_res_assign where resource_id = ?--update pro_gantt_task set responsible_id = ? ,responsible = ? where task_id = ?
这里只对SQL Server2008 测试通过,不知道Oracle/Mysql 其他的数据库还没测试;
- SQL语句的写法:Update、Case、 Select 一起的用法
- SQL语句的写法:Update、Case、 Select 一起的用法
- SQL语句的写法:update语句中 case...when 用法
- sql语句update中多个case/when的写法
- mysql 之SQL语句--NSERT SELECT ON DUPLICATE KEY UPDATE的写法
- SELECT语句中的for update的用法
- SQL:select case when的一些用法
- SQL:select case when的一些用法
- sql server select case when的用法
- 一个SQL语句的用法。Case 用法
- sql server的update select语句
- ACCESS支持标准SQL语句的SELECT CASE 语句么
- SQL语句中CASE函数的用法
- SQL语句----CASE WHEN 的用法简介
- SQL语句中 CASE 的用法
- sql中case语句的用法浅谈
- MYSQL update多条Select出来的数据 SQL写法
- UPDATE、INSERT、CASE的用法
- install wife
- NGUI八方向
- bios中断表
- QQ2006消息轰炸
- Windows 60个常用API
- SQL语句的写法:Update、Case、 Select 一起的用法
- 妙用Update Select
- 存储过程
- 程序员技术练级攻略
- 略谈如何在对话框创建视图类画图
- Linux undefined reference to `cos'
- 圆形可滑动菜单(可以动态添加菜单项)
- wince编译
- 整合Cocos2D的Documentation到Xcode的Documentation中