经典笛卡尔积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. 《深入理解Java虚拟机》笔记--第二章、Java内存区域与内存溢出异常

    Java程序员把内存的控制权交给了Java虚拟机.在Java虚拟机内存管理机制的帮助下,程序员不再需要为每一个new操作写对应的delete/free代码,而且不容易出现内存泄露和溢出. 虚拟机在执行 ...

  2. Percona XtraDB Cluster(PXC) Mysql 集群

    Percona XtraDB Cluster(PXC)   ---原理介绍篇         目录 一.简介 1 二.优缺点 2 三.区别/局限性 3 四. PXC复制原理 4 五. 服务解释 5   ...

  3. 湖南省第六届省赛题 Biggest Number (dfs+bfs,好题)

    Biggest Number 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 You have a maze with obstacles and non-zero di ...

  4. hdu 1849(巴什博弈)

    Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. [loj6039]「雅礼集训 2017 Day5」珠宝 dp+决策单调性+分治

    https://loj.ac/problem/6039 我们设dp[i][j]表示考虑所有价值小于等于i的物品,带了j块钱的最大吸引力. 对于ci相同的物品,我们一定是从大到小选k个物品,又发现最大的 ...

  6. Java Hibernate和.Net EntityFramework 如何在提交事务之前 就拿到需要新增实体的Id

    在Hibernate中很容易做到这一点,因为hibernate在事务commit之前  还有一个save方法,这个save方法就可以持久化并且拿到Id. 但是EF并不可以呀,EF是将对象标记为新增状态 ...

  7. 编译PHP并与Ngnix整合

    nginx本身不能处理PHP,它只是个web服务器,当接收到请求后,如果是php请求,则发给php解释器处理,并把结果返回给客户端. nginx一般是把请求发fastcgi管理进程处理,fascgi管 ...

  8. vue表格导入

    <input id="upload" type="file" @change="importfxx(this)"  accept=&q ...

  9. keil中的memory model

    这两天仿真遇到的怪事真的是一大堆. 还是读写Flash的代码.keil编译OK,但是仿真就是莫名其妙地挂掉出现一些乱七八糟的事情. 后面发现是keil 中的memory model勾选错了,勾选的是l ...

  10. Django项目中模板标签及模板的继承与引用【网站中快速布置广告】

    Django项目中模板标签及模板的继承与引用 常见模板标签 {% static %} {% for x in range(x) %}{% endfor %} 循环的序号{% forloop %} 循环 ...