zoukankan      html  css  js  c++  java
  • 经典笛卡尔积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;

  • 相关阅读:
    注册登录
    ASP.NET常用编程代码(一)
    HTML、CSS、JS、PHP 的学习顺序~(零基础初学者)
    如何学习javascript?(转)
    如何完全卸载SQL Server 2005
    如何给网页标题栏上添加图标(favicon.ico)
    网页制作常用代码
    网页颜色代码对照表
    ASP.NET常用编程代码(二)
    50个PHOTOSHOP快捷键技能!
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3241341.html
Copyright © 2011-2022 走看看