经典笛卡尔积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 ...
随机推荐
- vmware linux虚拟机连接ip设置
首先: 点击VMware 编辑->虚拟网络编辑器: 然后选中VMnet8的查看NAT设置: 上图第二步(记下红框中网关地址和子网掩码): 第三步(用于设置虚拟机地址范围): 接下来就是设置虚拟机 ...
- LeetCode741. Cherry Pickup
https://leetcode.com/problems/cherry-pickup/description/ In a N x N grid representing a field of che ...
- 洛谷 P1957 口算练习题 题解
题目传送门 这道题是考字符串处理,另外输入要使用c++的cin的神奇功能. #include<bits/stdc++.h> using namespace std; int n;char ...
- Windows下 Tensorflow安装问题: Could not find a version that satisfies the requirement tensorflow
Tensorflow 需要 Python 3.5/3.6 64bit 版本: 具体的安装方式可查看:https://www.tensorflow.org/install/install_window ...
- linux tar gzip 命令用法
语法:tar [主选项+辅选项] 文件或者目录 使用该命令时,主选项是必须要有的,它告诉tar要做什么事情,辅选项是辅助使用的,可以选用. 主选项: -c: 建立压缩档案-x:解压-t:查看内容-r: ...
- 自定义寄存器出现error C142: 'SFR': invalid base address
今天打算自定义一个.H文件来写写代码.自定义寄存器的时候发现出现这样的问题7816.H(5): error C142: 'SFR': invalid base address. 下面是我自定义的寄存器 ...
- JAVAEE学习——hibernate01:简介、搭建、配置文件详解、API详解和CRM练习:保存客户
今日学习:hibernate是什么 一.hibernate是什么 框架是什么: 1.框架是用来提高开发效率的 2.封装了好了一些功能.我们需要使用这些功能时,调用即可.不需要再手动实现. 3.所以框架 ...
- centos7 默认进入系统命令行模式修改
systemctl get-default #查看系统启动进入默认模式 systemctl set-default graphical.target #改成默认进入 图形界面模式 systemctl ...
- hp
命令组成hpacucli [parameter=value] 查看: 查看所有控制器状态 hpacucli ctrl all show 查看slot 0阵列信息详细状态 (可以查看物理磁盘和逻辑磁盘的 ...
- 初探 Spring Boot
近些年Spring Boot都特别火,一直都想来学习学习,奈何近期公司项目繁忙,一直都没有时间来学习,今天终于是休息一天,于是来一睹 SpringBoot 的风采. 一.什么是Spring Boot ...