请教多表查询语句写法?
时间:2011-12-16
来源:互联网
SQL code
上面的SQL语句已经测试,能正常执行并查询出数据。
现在我想在 couponbroadcast 表中再拿一个state字段值出来。请问该怎样写?谢谢!
select c.id, c.corporationName, c.corporationNetName, nvl(m.PersonCount, 0) PersonCount, cg.name corpcategoryName, c.city || ' ' || c.section || ' ' || c.street area from (select f.toCorpId from follow f where f.state = 1 and f.corpid = 1323008 group by f.toCorpId) f inner join Corporation c on f.toCorpId = c.id inner join Corpservice s on c.id = s.corporationid and s.servicename = 5 and s.state = 1 inner join corpcategory cg on c.categoryid_l0 = cg.id left join (select m.merchant, count(1) PersonCount from abc m group by m.merchant) m on c.customername = m.merchant where c.id not in (select c.id from corporation c where c.fatherid = 1323008 and c.state = 1) and c.id not in (select decode(p.corpid,1323008,p.tocorpid,p.corpid) corpid from couponbroadcast p where p.tocorpid = 1323008 or p.corpid = 1323008 and p.state != 3 and p.state != 4)
上面的SQL语句已经测试,能正常执行并查询出数据。
现在我想在 couponbroadcast 表中再拿一个state字段值出来。请问该怎样写?谢谢!
作者: cbcman 发布时间: 2011-12-16
couponbroadcast 并不在 或者生成的集合在from 中
只在where中存在呢。
只在where中存在呢。
作者: lxpbs8851 发布时间: 2011-12-16
个人感觉用(+)会简单很多
作者: shanzhifeng1 发布时间: 2011-12-16
couponbroadcast 只存在于子查询中 当然查不了state字段 要么再单独连下表couponbroadcast
作者: HJ_daxian 发布时间: 2011-12-16
给你个简单但是不效率的方法,在select部位加上一个子查询:
SQL code
SQL code
select c.id, c.corporationName, c.corporationNetName, nvl(m.PersonCount, 0) PersonCount, cg.name corpcategoryName, c.city || ' ' || c.section || ' ' || c.street area, (select state from couponbroadcast where ......) -- where条件要保证结果集最多1条记录 from (select f.toCorpId
作者: xiaobn_cn 发布时间: 2011-12-16
试试这个
SQL code
SQL code
select c.id, c.corporationName, c.corporationNetName, nvl(m.PersonCount, 0) PersonCount, cg.name corpcategoryName, c.city || ' ' || c.section || ' ' || c.street area, st.state from (select f.toCorpId from follow f where f.state = 1 and f.corpid = 1323008 group by f.toCorpId) f inner join Corporation c on f.toCorpId = c.id inner join Corpservice s on c.id = s.corporationid and s.servicename = 5 and s.state = 1 inner join corpcategory cg on c.categoryid_l0 = cg.id left join (select m.merchant, count(1) PersonCount from abc m group by m.merchant) m on c.customername = m.merchant left join (select decode(p.corpid,1323008,p.tocorpid,p.corpid) corpid, p.state from couponbroadcast p where p.tocorpid = 1323008 or p.corpid = 1323008 and p.state != 3 and p.state != 4) st on c.id=st.corpid where c.id not in (select c.id from corporation c where c.fatherid = 1323008 and c.state = 1) and st.corpid is null
作者: lxpbs8851 发布时间: 2011-12-16
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28