编写SQL查询---

时间:2013-05-14 07:07:47

标签: sqlplus

有人可以帮助重写此查询。我不确定我们是否可以通过编写查询来实现此结果,或者我们必须为此编写一个过程。

我需要在两个单独的列中使用此查询的结果,其中lm.listingmanagerid=bd.renteridlm.listingmanagerid<>bd.renterid位于单独的列中。 请帮帮我。

我希望选择部分中的两列(其中lm.listingmanagerid = bd.renterid和lm.listingmanagerid&lt;&gt; bd.renterid)

通过使用以下查询,我得到的结果是listingmanagerID与bookingdetails表匹配,我可以从不同列中的两个表中获得不匹配的ID select bd.listingid from bookingdetails bd, listingmanager lm where lm.listingmanagerid=bd.renterid

两个表的结构下面

CREATE TABLE BOOKINGDETAILS ( BOOKINGDETAILSID VARCHAR2(28) NOT NULL, LISTINGID VARCHAR2(28) NOT NULL, TRAVELLERPROTECTIONID VARCHAR2(28), TRAVELLERID VARCHAR2(28) NOT NULL, TRAVELLERNAME VARCHAR2(50) NOT NULL, CHECKINDATE DATE NOT NULL, CHECKOUTDATE DATE NOT NULL, NOOFGUEST NUMBER NOT NULL, TERMSANDCON LONG RAW, BOOKINGSTATUS NUMBER DEFAULT 0 NOT NULL, BOOKINGDATE DATE NOT NULL, UPDATEDATE DATE, UPDATEDBY VARCHAR2(50) NOT NULL, CURRENCYCODE VARCHAR2(10), BOOKINGAMOUNT FLOAT, AOVSERVICEFEE FLOAT, AMENITYWITHFEE VARCHAR2(3000), OCA NUMBER NOT NULL, RENTALTOTALAMOUNT FLOAT, AMENITIESFEE FLOAT, RENTERID VARCHAR2(28), CANCELLATIONAMOUNT FLOAT, PAYMENTID VARCHAR2(28), CCNUMBER VARCHAR2(30), LISTINGMANAGERID VARCHAR2(28), OWNERVIEWSTATUS NUMBER(2) DEFAULT 0, OWNERVIEWSTATUSDATE DATE, BOOKINGSTATUSDATE DATE, OWNERPAYOUTSTATUS NUMBER(2) DEFAULT 0, OWNERPAYOUTSTATUSDATE DATE, DISPUTESTATUS NUMBER(2) DEFAULT 0, DISPUTESTATUSDATE DATE, TRAVELLERPAYMENTSTATUS NUMBER(2) DEFAULT 0, TRAVELLERPAYMENTSTATUSDATE DATE, REJECTIONREASON NUMBER(10), REJECTIONREASONDETAIL VARCHAR2(200), CONSTRAINT SYS_C004345 PRIMARY KEY ( BOOKINGDETAILSID ) );

CREATE TABLE LISTINGMANAGER ( LISTINGMANAGERID VARCHAR2(28) NOT NULL, FIRSTNAME VARCHAR2(30) NOT NULL, LASTNAME VARCHAR2(30) NOT NULL, PRIMARYPHONE VARCHAR2(20) NOT NULL, ALTERNATEPHONE VARCHAR2(20), EMAIL VARCHAR2(100) NOT NULL, USERNAME VARCHAR2(100) NOT NULL, PASSWORD VARCHAR2(32) NOT NULL, RECALLGUID VARCHAR2(32), CUSTOMERSINCE DATE, LASTUPDATED DATE NOT NULL, UPDATEDBY VARCHAR2(28) NOT NULL, OCA NUMBER NOT NULL, PWCHANGEREQUIRED VARCHAR2(1), PWEXPIREDATE DATE, LASTLOGIN DATE, CALLINGHOURS VARCHAR2(200), TIMEZONEID VARCHAR2(20), CREATEDATE DATE, CREATEIPADDRESS VARCHAR2(16), AUTORENEWFLAG VARCHAR2(1), AUTORENEWREMOVEDDATE DATE, AUTORENEWDATE DATE, ISSUPPLIER VARCHAR2(1) DEFAULT 'N', PREFFEREDLANGUAGE VARCHAR2(2), LOCALEID VARCHAR2(2), ADDRESS1 VARCHAR2(50), ADDRESS2 VARCHAR2(50), CITYID VARCHAR2(28), COUNTRYID VARCHAR2(28), STATEPROVINCEID VARCHAR2(28), POSTALCODE VARCHAR2(10), REGISTRATIONSOURCE VARCHAR2(1), PPCTYPEID VARCHAR2(28), ABOUTME VARCHAR2(2000), PICTUREFILEPATH VARCHAR2(200), ISPROFILEPICTUREDISPLAY VARCHAR2(1), GHOSTUSER VARCHAR2(1) DEFAULT 'N', PROFILEID VARCHAR2(10), CONSTRAINT SYS_C005739 PRIMARY KEY ( LISTINGMANAGERID ) , CONSTRAINT USERNAME_CONSTRAINT UNIQUE(USERNAME) );

由于

1 个答案:

答案 0 :(得分:1)

SELECT bookingdetails.listingid AS owner from bookingdetails INNER JOIN listingmanager ON  listingmanager.listingmanagerid = bookingdetails.renterid

可能,你需要这个。