经典笛卡尔积SQL
经典笛卡尔积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的更多相关文章
- 回首经典的SQL Server 2005
原创文章转载请注明出处:@协思, http://zeeman.cnblogs.com SQL Server是我使用时间最长的数据库,算起来已经有10年了.上世纪90年代,微软在软件开发的所有领域高歌猛 ...
- 几道经典的SQL笔试题目
几道经典的SQL笔试题目(有答案) (1)表名:购物信息 购物人 商品名称 数量 A 甲 2 B 乙 ...
- 一些经典===>>用SQL语句操作数据
用SQL语句操作数据 结构化查询语言(Structured Query Language)简称SQL(发音:/ˈes kjuː ˈel/ "S-Q-L"),是一种特殊目的的编程语言 ...
- 经典的SQL面试题
SQL中 inner join. left join .right join. outer join之间的区别 A表(a1,b1,c1) B表(a2,b2) a1 b1 c1 a2 b2 01 数学 ...
- 11个实用经典的SQL小贴士
学习工作之余,在没有要解决问题的压力之下,还是建议系统的看看书,对于一些认为没啥用的知识点,也建议去仔细的看看,练练手,说不定什么时候就用到了,到时也好有针对性的去查,不至于盲目的按照自己的思路,重复 ...
- 经典的SQL语句面试题
Student(S#,Sname,Sage,Ssex) 学生表 Course(C#,Cname,T#) 课程表 SC(S#,C#,score) 成绩表 Teacher(T#,Tname) 教师表 问题 ...
- 经典的SQL语句面试题(转)
Student(S#,Sname,Sage,Ssex) 学生表Course(C#,Cname,T#) 课程表SC(S#,C#,score) 成绩表Teacher(T#,Tname) 教师表 问题:1. ...
- [置顶] 一道经典的sql面试题不同的写法
用一条SQL语句 查询出每门课都大于80分的学生姓名,表( #test)如下: Name Course Mark 张三 语文 81 张三 数学 75 李四 语文 76 李四 数学 90 王五 ...
- 【MySQL】经典数据库SQL语句编写练习题——SQL语句扫盲
[MySQL]数据库原理复习——SQL语言 对基本的SQL语句编写的练习题,其中的题目的答案可能会有多种书写方式. 1.题目1 1.1 关系模式 学生student:SNO:学号,SNAME:姓名,A ...
随机推荐
- 《深入理解Java虚拟机》笔记--第二章、Java内存区域与内存溢出异常
Java程序员把内存的控制权交给了Java虚拟机.在Java虚拟机内存管理机制的帮助下,程序员不再需要为每一个new操作写对应的delete/free代码,而且不容易出现内存泄露和溢出. 虚拟机在执行 ...
- python不可以打印.doc文件
[背景] 需求: 打印word文件 模块: python-docx [问题] 传递xxx.doc文件给python脚本,执行后,控制台没有内容输出 经查询后了解到,大致理由: doc是早一代的word ...
- 苹果receipt样例
使用[[NSBundle mainBundle] appStoreReceiptURL]方式获取receipt (iOS7及以上获取receipt的方法) 普通付费 "latest_rece ...
- Spring学习-理解IOC和依赖注入
最近刚买了一本介绍ssm框架的书,里面主要对Mybatis.spring.springmvc和redis做了很多的讲解,个人觉得虽然有的内容我看不懂,但是整体上还是不错的.最近正在学习中,一边学习一边 ...
- apache Apache winnt_accept: Asynchronous AcceptEx failed 错误的解决
httpd配置文件中添加: AcceptFilter http noneAcceptFilter https none apache优化: http://blog.csdn.net/hytfly/ar ...
- 程序员必备的代码审查(Code Review)清单
在我们关于高效代码审查的博文中,我们建议使用一个检查清单.在代码审查中,检查清单是一个非常好的工具——它们保证了审查可以在你的团队中始终如一的进行.它们也是一种保证常见问题能够被发现并被解决的便利方式 ...
- Python内置函数__slots__
''' 1.__slots__是什么:是一个类变量,变量值可以是列表,元祖,或者可迭代对象,也可以是一个字符串(意味着所有实例只有一个数据属性) 2.引子:使用点来访问属性本质就是在访问类或者对象的_ ...
- scrapy保存csv文件有空行的解决方案
比如现在我有一个名为test的爬虫,运行爬虫后将结果保存到test.csv文件 默认情况下,我执行scrapy crawl test -o test.csv ,得到的结果可能就是下面这种情况,每两行中 ...
- zookeeper分布式算法和部署
算法摘要 安装 配置 监控 创建节点 二阶段提交(Two-Phase Commit) 投票和执行 协调者向参与者发送事务内容,询问是否可以提交,各参与者节点执行事务并向协调者反馈 如果所有参与者反馈y ...
- Educational Codeforces Round 38 部分题解
D. Buy a Ticket 分析 建一个源点,连向所有结点,边的花费为那个结点的花费,图中原有的边花费翻倍,最后跑一遍最短路即可. code #include<bits/stdc++.h&g ...