经典笛卡尔积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 ...
随机推荐
- HDU 4725 The Shortest Path in Nya Graph(spfa+虚拟点建图)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4725 题目大意:有n层,n个点分布在这些层上,相邻层的点是可以联通的且距离为c,还有额外给出了m个条边 ...
- Educational Codeforces Round 25 D - Suitable Replacement(贪心)
题目大意:给你字符串s,和t,字符串s中的'?'可以用字符串t中的字符代替,要求使得最后得到的字符串s(可以将s中的字符位置两两交换,任意位置任意次数)中含有的子串t最多. 解题思路: 因为知道s中的 ...
- MySQL之基础功能
一.视图 视图:是一个虚拟表,其内容由查询定义.同真实的表一样,视图包含一系列带有名称的列和行数据 视图有如下特点: 1. 视图的列可以来自不同的表,是表的抽象和逻辑意义上建立的新关系. 2. 视图是 ...
- 专题-Delphi/C++ Builder多线程编程与调试
[目录] Delphi.C++ Builder多线程程序编码调试的一点经验谈 多线程程序的填坑笔记和多线程编程应该遵循的规则(天地弦) 多线程编程中死锁问题的跟踪与解决 临界.多重读独占写多线程同步测 ...
- virtualenv python的虚拟环境
官网:https://virtualenv.pypa.io/en/stable/userguide/ virtualenv通过创建独立Python开发环境的工具, 来解决依赖.版本问题 基本使用: d ...
- loadruner关联web_reg_save_param
语法int web_reg_save_param(const char *ParamName, <list of Attributes>, LAST); 参数说明: • ParamName ...
- run-time setting 中设置simulate browser cache 选项详解
Browser Emulation: Simulate browser cache:配置Vuser模拟带缓存的浏览器.缺省缓存是被允许的, 可以通过禁止该选项来使得所有VUser模拟的浏览器都不 ...
- NEO4j简单入门
Neo4j是: 一个开源 无Schema 没有SQL 图形数据库 图形数据库也称为图形数据库管理系统或GDBMS. Neo4j的官方网站:http://www.neo4j.org Neo4j的优点 它 ...
- MySQL 5.7 安装完成后,首次登陆的几个问题
Server:CentOS 7.0 MySQL : 5.7.20 MySQL Community Server (GPL) 1.首次登陆后修改密码: 根据安装时的选择不同,有mysqld_safe用m ...
- mySQL 的 2个分类
1.将如下表中的每门成绩都大于80分的人名? 张三 语文 81 张三 数学 75 李四 语文 76 李四 数学 90 王五 语文 81 王五 数学 100 王五 英语 90 select * from ...