经典笛卡尔积SQL:

下面的SQL会造成笛卡尔积:

insert into tydic.temp_0731 select a.user_id,a.province_code,b.attr_code from tydic.pline_user_tmp a,tydic.pline_attr_tmp b
where a.user_id = b.user_id
and (a.service_id = '80000009'  and b.attr_code in ('10000500',
'10000501',
'10000502',
'10000503'
)) or (a.service_id='80000026' and b.attr_code in ('10000105',
'10000112',
'10000128',
'10000129'
)) or (a.service_id='80000014' and b.attr_code in ('10000500',
'10000501',
'10000502',
'10001302'
)) or (a.service_id='80000015' and b.attr_code in ('10000501',
'10000502',
'10001302',
'10001303'
)) or (a.service_id='80000029' and b.attr_code in ('10000500',
'10000507',
'10000508',
'10000501'
)) or (a.service_id='80000032' and b.attr_code in (
'10000500',
'10001300',
'10000507')) or (a.service_id='80000030' and b.attr_code in (
'10001025',
'10001026',
'10001022'
)) or (a.service_id='80000033' and b.attr_code in (
'10001020',
'10000502',
'10000505')) or (a.service_id='80000016' and b.attr_code in (
'10001010',
'10001011',
'10001013'
)) or (a.service_id='80000007' and b.attr_code in (
'10001007',
'10001008',
'10001009'
)) or (a.service_id='80000023' and b.attr_code in (
'10001001',
'10001005',
'10001006'
)) or (a.service_id='80000034' and b.attr_code in (
'10001001',
'10001002',
'10000100'
))  or (a.service_id='80000017' and b.attr_code in (
'10001101',
'10001102',
'10001103'
));
commit;

经过下面改造,不会出现笛卡尔积:

insert into tydic.temp_0731 select a.user_id,a.province_code,b.attr_code from tydic.pline_user_tmp a,tydic.pline_attr_tmp b
where a.user_id = b.user_id
and( (a.service_id = '80000009'  and b.attr_code in ('10000500',
'10000501',
'10000502',
'10000503'
)) or (a.service_id='80000026' and b.attr_code in ('10000105',
'10000112',
'10000128',
'10000129'
)) or (a.service_id='80000014' and b.attr_code in ('10000500',
'10000501',
'10000502',
'10001302'
)) or (a.service_id='80000015' and b.attr_code in ('10000501',
'10000502',
'10001302',
'10001303'
)) or (a.service_id='80000029' and b.attr_code in ('10000500',
'10000507',
'10000508',
'10000501'
)) or (a.service_id='80000032' and b.attr_code in (
'10000500',
'10001300',
'10000507')) or (a.service_id='80000030' and b.attr_code in (
'10001025',
'10001026',
'10001022'
)) or (a.service_id='80000033' and b.attr_code in (
'10001020',
'10000502',
'10000505')) or (a.service_id='80000016' and b.attr_code in (
'10001010',
'10001011',
'10001013'
)) or (a.service_id='80000007' and b.attr_code in (
'10001007',
'10001008',
'10001009'
)) or (a.service_id='80000023' and b.attr_code in (
'10001001',
'10001005',
'10001006'
)) or (a.service_id='80000034' and b.attr_code in (
'10001001',
'10001002',
'10000100'
))  or (a.service_id='80000017' and b.attr_code in (
'10001101',
'10001102',
'10001103'
)));
commit;

经典笛卡尔积SQL的更多相关文章

  1. 回首经典的SQL Server 2005

    原创文章转载请注明出处:@协思, http://zeeman.cnblogs.com SQL Server是我使用时间最长的数据库,算起来已经有10年了.上世纪90年代,微软在软件开发的所有领域高歌猛 ...

  2. 几道经典的SQL笔试题目

      几道经典的SQL笔试题目(有答案) (1)表名:购物信息 购物人      商品名称     数量 A            甲          2 B            乙        ...

  3. 一些经典===>>用SQL语句操作数据

    用SQL语句操作数据 结构化查询语言(Structured Query Language)简称SQL(发音:/ˈes kjuː ˈel/ "S-Q-L"),是一种特殊目的的编程语言 ...

  4. 经典的SQL面试题

    SQL中 inner join. left join .right join. outer join之间的区别 A表(a1,b1,c1) B表(a2,b2) a1 b1 c1 a2 b2 01 数学 ...

  5. 11个实用经典的SQL小贴士

    学习工作之余,在没有要解决问题的压力之下,还是建议系统的看看书,对于一些认为没啥用的知识点,也建议去仔细的看看,练练手,说不定什么时候就用到了,到时也好有针对性的去查,不至于盲目的按照自己的思路,重复 ...

  6. 经典的SQL语句面试题

    Student(S#,Sname,Sage,Ssex) 学生表 Course(C#,Cname,T#) 课程表 SC(S#,C#,score) 成绩表 Teacher(T#,Tname) 教师表 问题 ...

  7. 经典的SQL语句面试题(转)

    Student(S#,Sname,Sage,Ssex) 学生表Course(C#,Cname,T#) 课程表SC(S#,C#,score) 成绩表Teacher(T#,Tname) 教师表 问题:1. ...

  8. [置顶] 一道经典的sql面试题不同的写法

    用一条SQL语句   查询出每门课都大于80分的学生姓名,表( #test)如下:    Name Course Mark 张三 语文 81 张三 数学 75 李四 语文 76 李四 数学 90 王五 ...

  9. 【MySQL】经典数据库SQL语句编写练习题——SQL语句扫盲

    [MySQL]数据库原理复习——SQL语言 对基本的SQL语句编写的练习题,其中的题目的答案可能会有多种书写方式. 1.题目1 1.1 关系模式 学生student:SNO:学号,SNAME:姓名,A ...

随机推荐

  1. Go语言入门之指针的使用

    指针的使用: package main import "fmt" func zhi(){ a:= var b *int=&a //声明指针并赋值 *b=3 //改变内存地址 ...

  2. Source Insight 4.0 文件类型、编码格式、tab转空格、tab键自动补全设置。。。

    1.编码格式  -- 在 Options->Preferences->Files 中的最下面,Default enconding 为 UTF-8 2.tab转空格 其他相关设置如下: 以下 ...

  3. WMI技术介绍和应用——WMI概述

    https://blog.csdn.net/breaksoftware/article/details/8424317

  4. 如何使用Inno Setup Compiler制作安装软件包

    工具/原料   Inno Setup Compiler汉化版软件 方法/步骤     启动Inno Setup Compiler汉化版软件.   选择创建新的空白脚本文件,按确定.   然后按下一步. ...

  5. Python全栈开发之4、内置函数、文件操作和递归

    转载请注明出处http://www.cnblogs.com/Wxtrkbc/p/5476760.html 一.内置函数 Python的内置函数有许多,下面的这张图全部列举出来了,然后我会把一些常用的拿 ...

  6. spring_150906_sqlmapclientdaosupport_getSqlMapClientTemplate

    添加到ibatis相关jar包! 实体类: package com.spring.model; public class DogPet { private int id; private String ...

  7. bzoj 1854 并查集 + 贪心

    思路:这个题的并查集用的好NB啊, 我们把伤害看成图上的点,武器作为边,对于一个联通块来说, 如果是一棵大小为k的树,那么这个联通块里面有k - 1个伤害能被取到,如果图上有环那么k个值都能 取到,对 ...

  8. laravel windows安装(composer)

    1.安装composer参考windows 安装tp5 composer方式 2.先配置好本地虚拟域名,在cmd里面切换到网站根目录 ... 3.安装成功之后,在浏览器输入已配置的虚拟域名我的是,la ...

  9. jquery 选中 未选的几种方法

    ---恢复内容开始--- jquery判断checked的三种方法:.attr('checked):   //看版本1.6+返回:”checked”或”undefined” ;1.5-返回:true或 ...

  10. Markdown 格式如何转换成 Word?

    参考资料:https://www.zhihu.com/question/22972843/answer/136008865 markdown语法简洁,写作效率极高,非常适合网络博客.邮件.笔记等非正式 ...