<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆心得

    記我所見(jiàn),記我所想

    BlogJava 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
      34 Posts :: 0 Stories :: 16 Comments :: 0 Trackbacks

    用數(shù)學(xué)里集合的思想去解決數(shù)據(jù)庫(kù)表的問(wèn)題,可以幫助我們清晰的分析和解決問(wèn)題。

    查詢不滿足工作要求的人

    ?

    人名 ?? 工作名 ? 不滿足條件 ? 人條件 ? 工作條件

    張三 ?? 搬運(yùn)工 ??? 年齡 ????? 8???????? 青年

    李四 ?? 教師 ????? 愛(ài)好 ????? 體育 ????? 畫畫

    ?

    在表里隨便添點(diǎn)數(shù)據(jù)

    ?

    查詢 比如工作表里 搬運(yùn)工 需要青年 ? 張三才 8 所以不符合條件

    ?

    工作表里要求 工作 愛(ài)好是畫畫的 ? 李四的愛(ài)好是 體育 所以也不符合條件 就是把 這種不符合條件的全都查出來(lái)

    ?



    關(guān)于多表查詢的一個(gè)題
    sql腳本如下
    生成表及關(guān)系的腳本:
    /*==============================================================*/
    /* DBMS name:????? Microsoft SQL Server 2000??????????????????? */
    /* Created on:???? 2007-7-11 12:48:23?????????????????????????? */
    /*==============================================================*/


    alter table WORKS
    ?? drop constraint FK_WORKS_REFERENCE_AGE
    go

    alter table WORKS
    ?? drop constraint FK_WORKS_REFERENCE_FAVERATE
    go

    alter table WORKS
    ?? drop constraint FK_WORKS_REFERENCE_ROLE
    go

    alter table rights
    ?? drop constraint FK_RIGHTS_REFERENCE_ROLE
    go

    alter table rights
    ?? drop constraint FK_RIGHTS_REFERENCE_USERS
    go

    alter table users
    ?? drop constraint FK_USERS_REFERENCE_FAVERATE
    go

    if exists (select 1
    ??????????? from? sysobjects
    ?????????? where? id = object_id('WORKS')
    ??????????? and?? type = 'U')
    ?? drop table WORKS
    go

    if exists (select 1
    ??????????? from? sysobjects
    ?????????? where? id = object_id('age')
    ??????????? and?? type = 'U')
    ?? drop table age
    go

    if exists (select 1
    ??????????? from? sysobjects
    ?????????? where? id = object_id('faverate')
    ??????????? and?? type = 'U')
    ?? drop table faverate
    go

    if exists (select 1
    ??????????? from? sysobjects
    ?????????? where? id = object_id('rights')
    ??????????? and?? type = 'U')
    ?? drop table rights
    go

    if exists (select 1
    ??????????? from? sysobjects
    ?????????? where? id = object_id('role')
    ??????????? and?? type = 'U')
    ?? drop table role
    go

    if exists (select 1
    ??????????? from? sysobjects
    ?????????? where? id = object_id('users')
    ??????????? and?? type = 'U')
    ?? drop table users
    go

    /*==============================================================*/
    /* Table: WORKS???????????????????????????????????????????????? */
    /*==============================================================*/
    create table WORKS (
    ?? id?????????????????? int????????????????? not null,
    ?? name???????????????? char(1)????????????? null,
    ?? age????????????????? int????????????????? null,
    ?? faverate???????????? int????????????????? null,
    ?? role???????????????? int????????????????? null,
    ?? constraint PK_WORKS primary key? (id)
    )
    go

    execute sp_addextendedproperty 'MS_Description',
    ?? '工作表',
    ?? 'user', '', 'table', 'WORKS'
    go

    /*==============================================================*/
    /* Table: age?????????????????????????????????????????????????? */
    /*==============================================================*/
    create table age (
    ?? id?????????????????? int????????????????? not null,
    ?? type???????????????? char(1)????????????? null,
    ?? span???????????????? int????????????????? null,
    ?? constraint PK_AGE primary key? (id)
    )
    go

    execute sp_addextendedproperty 'MS_Description',
    ?? '年齡表',
    ?? 'user', '', 'table', 'age'
    go

    /*==============================================================*/
    /* Table: faverate????????????????????????????????????????????? */
    /*==============================================================*/
    create table faverate (
    ?? id?????????????????? int????????????????? not null,
    ?? type???????????????? char(1)????????????? null,
    ?? description????????? char(1)????????????? null,
    ?? constraint PK_FAVERATE primary key? (id)
    )
    go

    execute sp_addextendedproperty 'MS_Description',
    ?? '愛(ài)好表',
    ?? 'user', '', 'table', 'faverate'
    go

    /*==============================================================*/
    /* Table: rights??????????????????????????????????????????????? */
    /*==============================================================*/
    create table rights (
    ?? id?????????????????? int????????????????? not null,
    ?? uid????????????????? int????????????????? null,
    ?? rid????????????????? int????????????????? null,
    ?? constraint PK_RIGHTS primary key? (id)
    )
    go

    execute sp_addextendedproperty 'MS_Description',
    ?? '權(quán)限表',
    ?? 'user', '', 'table', 'rights'
    go

    /*==============================================================*/
    /* Table: role????????????????????????????????????????????????? */
    /*==============================================================*/
    create table role (
    ?? id?????????????????? int????????????????? not null,
    ?? name???????????????? char(1)????????????? null,
    ?? constraint PK_ROLE primary key? (id)
    )
    go

    execute sp_addextendedproperty 'MS_Description',
    ?? '角色表',
    ?? 'user', '', 'table', 'role'
    go

    /*==============================================================*/
    /* Table: users???????????????????????????????????????????????? */
    /*==============================================================*/
    create table users (
    ?? id?????????????????? int????????????????? not null,
    ?? name???????????????? char(1)????????????? null,
    ?? age????????????????? int????????????????? null,
    ?? faverate???????????? int????????????????? null,
    ?? sex????????????????? char(1)????????????? null,
    ?? constraint PK_USERS primary key? (id)
    )
    go

    execute sp_addextendedproperty 'MS_Description',
    ?? '用戶表',
    ?? 'user', '', 'table', 'users'
    go

    alter table WORKS
    ?? add constraint FK_WORKS_REFERENCE_AGE foreign key (age)
    ????? references age (id)
    go

    alter table WORKS
    ?? add constraint FK_WORKS_REFERENCE_FAVERATE foreign key (faverate)
    ????? references faverate (id)
    go

    alter table WORKS
    ?? add constraint FK_WORKS_REFERENCE_ROLE foreign key (role)
    ????? references role (id)
    go

    alter table rights
    ?? add constraint FK_RIGHTS_REFERENCE_ROLE foreign key (rid)
    ????? references role (id)
    go

    alter table rights
    ?? add constraint FK_RIGHTS_REFERENCE_USERS foreign key (id)
    ????? references users (id)
    go

    alter table users
    ?? add constraint FK_USERS_REFERENCE_FAVERATE foreign key (faverate)
    ????? references faverate (id)
    go

    查詢腳本 :

    select * from AGE

    select * from FAVERATE
    select * from RIGHTS


    select * from ROLE

    select * from USERS
    select u.id as uid,u.name as uname,u.age as uage,u.faverate as ufaver,r.rid as rrid from USERS u,RIGHTS r where r.uid=uid

    ?

    select wid,age,faverate,role from WORKS

    select u.id as uid,u.age as uage,u.faverate as ufaver,r.rid as rrid from USERS u,RIGHTS r where r.uid=uid

    ?


    <--符合條件的工作-->
    select distinct w.wid,a.span as aspan,w.faverate as wfaver,v.uid,v.uage,v.ufaver from AGE a,WORKS w,

    ?(select u.id as uid,u.age as uage,u.faverate as ufaver,r.rid as rrid from USERS u,RIGHTS r

    ??where r.uid=uid) v

    where a.ageid=w.age and a.span=uage and w.faverate=v.ufaver

    ?


    <--不符合條件的工作-->
    select users.name 人名,works.name 工作名,v2.aspan 需求年齡,v2.uage 用戶年齡,v2.wfaver 需求愛(ài)好,v2.ufaver 用戶愛(ài)好 from users,works,

    (select distinct w.wid,a.span as aspan,w.faverate as wfaver,v.uid,v.uage,v.ufaver from AGE a,WORKS w,

    ?(select u.id as uid,u.age as uage,u.faverate as ufaver,r.rid as rrid from USERS u,RIGHTS r

    ??where r.uid=uid) v

    ??????? where a.ageid=w.age and (a.span!=uage or w.faverate!=v.ufaver )) v2

    where v2.wid=works.wid and v2.uid=users.id order by users.name

    ?

    ?
    posted on 2007-07-11 14:03 源自有緣 閱讀(356) 評(píng)論(0)  編輯  收藏

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 青青免费在线视频| 一级毛片免费播放| 亚洲中文字幕在线乱码| 99ee6热久久免费精品6| 国产成人精品日本亚洲18图| 日韩成人免费aa在线看| 鲁丝片一区二区三区免费| 亚洲五月综合网色九月色| 亚洲国产综合久久天堂| 222www在线观看免费| 亚洲AV网一区二区三区 | 最近最新MV在线观看免费高清| 色九月亚洲综合网| 亚洲综合在线视频| 四虎永久在线精品免费观看地址| 国产麻豆成人传媒免费观看| 亚洲成a人无码亚洲成www牛牛| 亚洲Av综合色区无码专区桃色| 免费鲁丝片一级观看| 久久国产色AV免费观看| 免费人妻精品一区二区三区| 亚洲电影唐人社一区二区| 亚洲国产精品日韩专区AV| 色se01短视频永久免费| 国产福利在线观看永久免费| 亚洲沟沟美女亚洲沟沟| 国产在线观看www鲁啊鲁免费| 99爱在线精品视频免费观看9| 精品国产日韩亚洲一区91| 亚洲最大黄色网址| 国产AV无码专区亚洲AV漫画| 在线a毛片免费视频观看| 午夜免费福利视频| 99视频在线免费观看| 美女裸体无遮挡免费视频网站| 亚洲av无码国产综合专区| 亚洲AV无码成人专区片在线观看 | 亚洲成av人在片观看| 最近2019中文字幕免费看最新| 1000部拍拍拍18勿入免费视频下载 | 91精品啪在线观看国产线免费|