Records that are common between user

I have 3 users in the schema.
User1
UserB
UserC
PURCHASE table name exists in all three data diagram above
As
UserA-> purchase - id_no, active_flag
UserB-> purchase - id_no, active_flag
UserC-> purchase - id_no (note there is no active_flag in this scheme.


I want to choose the user who has the same id_no by on all three.
I need to display ID_no, active_flag (weather it of active or not) and include the Source of recordings (name of user/schema)



1.I began with two tables...
2. I need to include the table shape UserC as well, please, not userc.purchase is not active_flag

Help, please...
 
select registration_number, flag_passive, cnt1 , cnt2 ,CASE WHEN CNT2 >0 THEN  ('USERA -  USERB')  END Source from (
   select id_no , active_flag, 
   sum(case when src=1 then 1 else 0 end) cnt1, 
   sum(case when src=2 then 1 else 0 end) cnt2 
   --sum(case when src=3 then 1 else 0 end) cnt2 
from 
   ( 
   select id_no , active_flag, 1 src from usera.purchase  
   union all
   select, id_no , active_flag 2 src from  userb.purchase 
   --union all
   --select id_no , ? from  userc.purchase  
   ) 
group by id_no , active_flag
) 
where cnt1 = cnt2;
 
CREATE TABLE purchase
(
  ID_no            NUMBER(12)  , 
  ACTIVE_FLAG_PASSIVE          VARCHAR2(1 CHAR) DEFAULT 0
)
 
Insert into purchase   ( ID_NO, ACTIVE_FLAG ) Values   (1119 , 0);
Insert into purchase   ( ID_NO, ACTIVE_FLAG ) Values   (1120 , 0);
Insert into purchase   ( ID_NO, ACTIVE_FLAG ) Values   (1119 , 1);
Insert into purchase   ( ID_NO, ACTIVE_FLAG ) Values   (1131 , 1);
Insert into purchase   ( ID_NO, ACTIVE_FLAG ) Values   (1145,  0);
Insert into purchase   ( ID_NO, ACTIVE_FLAG )  Values   (1146, 0);
COMMIT;
Published by: Smidreb on May 18, 2012 08:57

Hello

Maybe that's what you want:

WITH     combined_data     AS
(
   SELECT  id_no,        active_flag, 1  AS src     FROM usera.purchase
       UNION ALL
   SELECT  id_no,        active_flag, 2 AS src     FROM userb.purchase
       UNION ALL
   SELECT id_no, NULL AS active_flag, 3 AS src  FROM userc.purchase
)
,     got_src_cnt          AS
(
     SELECT  c.*
     ,      COUNT (DISTINCT src) OVER (PARTITION BY  id_no)
                    AS src_cnt
     FROM    combined_data  c
)
SELECT     id_no, active_flag, src
FROM     got_src_cnt
WHERE     src_cnt     = 3
;

Please post instructions and CREATE TABLE INSERT for examples of data, but you have posted only a single table. Isn't the whole point of this problem by comparing 3 different tables, which are not the same? Thanks for posting all the tables involved, and the results you want from this data.
For testing purposes, poretend all tbles are in the same pattern, with names like usera_purchase. It will be commonplace to chnge the '_' for a '.' later.
Always tell what version of Oracle you are using.

Tags: Database

Similar Questions

  • Selection of records that are greater than the current week or

    Hi I have a table with the table structure

    CREATE TABLE OMPPRODUCTION
    (
    LOCATIONID VARCHAR2 (200 BYTE) NOT NULL,
    IPC VARCHAR2 (200 BYTE) NOT NULL,
    PRODUCTIONWEEK VARCHAR2 (200 BYTE) NOT NULL,
    QUANTITY VARCHAR2 (2000 BYTE),
    PRODUCTIONCODE VARCHAR2 (2000 BYTE),
    MOULDQUANTITY VARCHAR2 (2000 BYTE),
    VARCHAR2 (2000 BYTE) SOURCE,
    VARCHAR2 (2000 BYTE) APPLICATION,
    COMMENTS VARCHAR2 (2000 BYTE),
    DATE OF TLM,
    ADSTAT CHAR (1 BYTE),
    SID NUMBER (10, 0),
    SECURITYLEVEL VARCHAR2 (100 BYTE),
    ENABLE CONSTRAINT PRIMARY KEY (LOCATIONID, CPI, PRODUCTIONWEEK) OMPPRODUCTION_PK
    )

    He has field PRODUCTIONWEEK that is to be given YYYYMMDD.

    I want to select records that are starting the week underway (Monday as departure day).

    for example, the date is 20120210 so I would choose the lines including the date more or equal to 20120206.

    Can someone guide me how it is possible?

    Published by: MaheshGx on 6 February 2012 16:16

    MaheshGx wrote:
    Select * from OMPPRODUCTION where to_number (to_char (to_date (productionweek, 'yyyymmdd'), 'WW')) > = to_number (to_char (sysdate, "WW"))

    Wow, why so complicated?

    You work with dates, so:

    (a) why the hell you store dates in a column VARCHAR2? (and worse yet, why is 200 bytes of length)? Store dates as the DATE. The optimizer based on CSSTidy will thank you. As well, you know, you won't be wasting space.
    (b) compare with the dates, not dates-converted dates - dates-converted-to-number numbers. Why do extra work when you have not to?

    Since you're after weeks from Monday, I'd go for the format mask "IW", since it is fixed and will always return the Monday of the current week ("WW" could return Sunday or Monday, depending on what are your NLS settings.) I'd rather have my labour code for those who executes it, regardless of their NLS settings).

    So, given the fact that your column is not the DATE data type, it would be more effective for you;

    select *
    from   ompproduction
    where  trunc(to_date(productionweek,'yyyymmdd'), 'iw') >= trunc(sysdate, 'iw');
    

    If you have an index on productionweek that you need help in this query, then I suggest to convert it to a basic index function.

  • Public records that are not visible in Windows Explorer

    A couple of days, when I tried an attachment to an e-mail, Public Documents didn t appear. Normally it is under Documents, next to My Documents. But now the Documents contains: My Documents and Documents (C :). And that the Documents (c) contains a folder named MAGIX_Video_deluxe_16, (paying) video editing software. This folder contains subfolders with nothing in it. In any case, I just moved because this isn't a big deal, as I find the search bar hollow. Later this program is not only happened with Hotmail, but also with Microsoft Office.

    But now he also started to happen when I open Windows Explorer. It's huge because no irritation only me, but my family also uses public records files a lot. Can someone help me?
    Edit: If I access public Documents hollow C:\Users\Public\Public Documents, the files are there. It's that when I access the files with Windows Explorer.

    Try this first,

    Then, open the site link,

    If the Public location does not appear browse it and click Add.

    Remove anything but my Documents in the example in the photo,

    Repeat for the other categories.

  • How to access a global variable that is common between the different baskets project library

    My project consist of several libraries, after generation the library project packed for each library, I find it cannot share data in a global variable between different packaged project library file. For example: packed project library #1 contains VI variables global wirte 'position' and give it a value '400 '. Library #2 present another VI project try to read this global variable, but he gave reading of is NULL not "400". Why has this happened? Is it possible to solve, welcome any help, I wll appreciate for this!

    If you understand what is happening here...

    When you build a PPL, it takes in the .lvlib and also all the dependencies of the .lvlib.

    In your case, when you generate the Test Task.lvlib in a .lvlibp, she also pulls on a copy of the DataProcess.lvlib:GlobalsVariable.vi because it's addictive to read GlobalVar.vi.

    When your application runs, you end up with two copies of GlobalsVariable.vi in memory:

    DataProcess.lvlibp:GlobalsVariable.vi

    AND

    Test Task.lvlibp:: GlobalsVariable.vi (I don't know how PPLs namespace dependencies... If there is still the DataProcess.lvlibp)

    Because they are different screws (i.e. in a different namespace), they have their own memory and that's why you can't access the data.

    Your Test Task.lvlibp calls the version of GlobalsVariable.vi, he pulled the dependencies.

    To solve this problem - you must ensure that Task.lvlibp of Test calls the version of GlobalsVariable.vi of the DataProcess.lvlibp - you'll need to replace all instances with the version of the PPL. Of course, if you run DataProcess in the development environment, then it will always be bad namespaced, hence the suggestion to put your global variable VI in is own PPL that you then use in the process of data and Test tasks.

  • Button to hide the records that are green shady

    In the form below, I am creating a custom button script (Javascript) that will hide all rows that currently are shaded green (border.fill.color.value = '204, 255, 204') in both Dynamics . The lines are grayed out when the user selects 'Green' of a menu object drop down located in each row.

    Thanks for your help with this.

    https://Acrobat.com/?d=hoXKsHVKALFdRwoS3Rnj7g

    Try this:

    for (var a = 0;<>

    for (var b = 0; b)<>

    If (LogoControls.ActionSubformA.all.item (a). Table1.row2.all.item (b). Status.rawValue == "Green") "

    LogoControls.ActionSubformA.all.item (a). Table1.row2.all.item (b) .its presence = "hidden";

    }

    }

    for (var a = 0;<>

    for (var b = 0; b)<>

    If (LogoControls.ActionSubformB.all.item (a). Table2.row2.all.item (b). Status.rawValue == "Green") "

    LogoControls.ActionSubformB.all.item (a). Table2.row2.all.item (b) .its presence = "hidden";

    }

    }

    and for a button display green, just change 'hidden' to 'visible '.

    Kyle

  • delete records that are related to another table

    I want to delete records from a table (A), these recordings has a relationship with another table (B)

    using a query to set these records is that I want to delete

    with B as
    (
    f select '2', '3' l double
    Union of all the
    f select '2', '3' l double
    Union of all the
    f select '4', '4' l double
    )


    Select * from A, B
    where B.f() > 3 and b. > 3
    and A.f. = B.f()
    and A.l = b.

    Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production


    Thanks in advance!

    Hello

    Here's one way:

    DELETE     a
    WHERE     f     > 3
    AND     l     > 3
    AND     (f, l)     IN (
                   SELECT  f, l
                   FROM     b
                     )
    ;
    
  • How to reject records that are incompatible with the definition ODI 11 g data store?

    Buenas tardes.

    Como puedo girls los looking than any stupid fulfil the definition of length of atributos as hay in el data do not store? For example, in a process of integration llega a cuyo campo has a length of 50 characters first_name registro, pero base datos solo supports 40 characters. ODI in este falla y being the run y yo Necesito UN than rechace este registro y con continue the run. How I can control this event?

    Of photos muchas gracias.

    Hello

    Ah yes, I forgot about it.

    You can fool ODI by changing the logical length of the column in the data store in the model.

    In this way the I$ table will have a length of more than time and you won't have the problem.

    Kind regards

    JeromeFr

    PS: Your English is above the average on this forum, don't you worry. Most of us is not English-speaking.

  • While sharing files between users, my itunes library disappeared from these two places. How can I get that back?

    As noted earlier, all trying to share music files from itunes between users on the same computer, my library of songs and videos have disappeared.  How can I cancel this and recover my music and videos?

    Hello

    I suggest you look in the folder iTunes, if the files are present there or not. The link given below shows the default location where the files are located. If they are present, then add them to the folder. Click on the link below.

    iTunes: how to share music between different accounts on a single computer

    http://support.Apple.com/kb/ht1203

    Thanks and regards.

    Thahaseena M
    Microsoft Answers Support Engineer.
    Visit ourMicrosoft answers feedback Forum and let us know what you think.

  • When I send an e-mail, sometimes there is no record that it was sent in my Outbox. In addition, there are an indication I'm getting all my e-mail.

    When I send an e-mail, sometimes there is no record that it was sent in my Outbox. In addition, there are an indication I'm getting all my e-mail. I checked this by sending me an e-mail to another e-mail system (the University mail) is a more recent. When my wife sends mail from the same account, there is never any document which it was sent. Can anyone help?

    original title: send and receive e-mail problem

    Make sure that under Tools | Options | Who send his game to save a copy in the sent items folder.  If his shows always do not up, so try to compact and repair the database (see www.oehelp.com/WMUtil/) and also to check antivirus or other 3rd party program interference.  See www.oehelp.com/OETips.aspx#3 and see the point #15 FYI.

    You can also send an email or copy it yourself to ensure you have messages and check on your mail server to ensure that spam filters are not block incoming messages you want.  Most mail servers now have filters.

    Steve

  • How to view a page that is common to all users

    Hello
    I want to display a message of welcome to every user that connects, send us this in presentation Services.

    Thank you
    Amit

    Hi Amit,

    Certainly, I understand your frustration. This process is usually a test of five minutes.

    Here's what I did:

    Part 1
    (1) recorded in presentation with a users Admin Services
    (2) click on settings-> Administration
    (3) click on "manage presentation catalog."
    (4) sailed towards the dashboard I was trying to make the default
    5) click on properties of this dashboard
    (6) to find the 'Path' attribute and copy (CTRL + C) information on the right NOTE: Important for this copy exactly as it appears here. This should not have a ' / ' at the end
    (7) put the following text in Notepad: SELECT "" OF DOUBLE NOTE: make sure that you do not introduce a space at the beginning or at the end during your copy & paste

    Part 2:
    (1) connect to the RPD in ONLINE mode
    (2) go in manage-> Variables
    (3) create an initialization block in the section session
    (4) PORTALPATH_IB the name and value of the data source to your application in Notepad: SELECT '' FROM DUAL
    (5) assign the SQL to a connection pool and click OK
    6) click on target to modify and click New and enter CHEMINPORTAIL for the name of the session variable. You should get a warning that it is a server variable. Click OK.
    7) click OK on your block of initialization
    (8) to save your changes

    Part 3:
    (1) ensure that your username has a dashboard by default 'by default'
    (2) sign out and then sign back in
    (3) you should be transferred to the CHEMINPORTAIL dashboard

    Good luck!

    -Joe

  • Need a script to find records and data warehouses that are near capacity.

    Guys,

    I'm new to Powershell faitly, is it possible to write a script tht will find virtual disks and data warehouses that are over 90% full?  I also want to export the results to an excel file.

    Thank you.

    For a 90% threshold, you let the value to 0.1.

    Calculate the free space as a percentage, so if the free space is less than or equal to 0.1 there is 10% or less available free space.

    Hope that makes sense.

  • Is there a way I can share files between users on the same Mac without an internet connection?

    Hello world!

    Quick question here: is there a way I can share files between users on the same Mac without an internet connection?

    I have two users say that A and B. If I go the long way via the 'Go' menu > 'Computer', I ended up being told to contact my computer or the network administrator for assistance. Both users are admin one and file sharing is allowed in system preferences... I have to admit that I use 10.9.5 because my MacBook Pro would not work with OS Xs national parks.

    Any ideas would be cool because I'm sure that it used to work fine with "Snow Leopard" without being connected to the internet - or should I just send an email to myself and recover the files on the other user :-) to recover my USB is

    Choose go to folder from the Finder Go menu, provide/Users/Shared/as the path and place the files.

    (142147)

  • I downloaded Firefox 4.0 compound that all my registered user names and passwords have been removed. How can I get them back safely?

    I need to retrieve my name of registered user and passwords that are automatically accessible but now are not displayed

    Where they recorded in Firefox or another program?

  • Error message 0 x 80004005 Unspecified error trying to connect to either network drives and printers network on the same network or network drives that are on the same workgroup.

    Essentially, this problem started last Friday and I tried all possible combinations and the thing that I know so far about how to solve this problem and I terribly need a solution because I use this laptop in a University to take notes and print them out / store them on the network. Right now I can ping both servers (one is a print server and the other server network file storage), but in both cases, when I try to connect to them using windows Explorer by the name of \\server name\share or \\printserver\ (the other usually allows me to see a table of printers that are in different locations and I choose who I connected to my laptop). The other method, I have tried to use, which works normally and does not now to map the network drive storage is the net use command, if I try this method, I will get a "system error 1231 has occurred the network location cannot be reached". The third method (which is more commonly used I think) is the ability to connect a network drive in Windows Explorer, usually if I use the third method, I get a response from the storage server file asking for user credentials, now I get the same error message as when I try to connect with the first method of.

    The biggest mystery of this all is that this happens regardless if I'm on the wired or wireless, and in both scenarios, I have access to the internet available, but as mentioned above, no access to storage or a network printer.

    * Use at your own risk, but it worked in my case (ensure you know / remember passwords field before doing so).

    If (since) you are using Windows 7 and you suddenly have problems connecting to a resource of the area (especially after a password reset):

    1) go to:->-> advanced user accounts manage user accounts-> manage passwords

    (2) If you see Windows credentials, delete them all.

  • "This action is only valid for products that are currently installed.

    A computer virus hit the machine so that the operating system must be reinstalled. In order to save the programs installed, I don't have a format and reapplied just windows + service pack. I saved the data user as shown in this link: http://pcworld.about.com/gi/dynamic/offsite.htm?site=http :// www.pcworld.com/howto/article/1, aid, 111652, pg, 4, 00.asp

    The office and programs are correct, but when I go to launch some programs (such as Excel, Word, WordPerfect), I get "this action is only valid for products that are current installed. I found a MS fix, but it doesn't install it stating that the level of the OS already contains the fix. I also found a pointer to move to the word 'Detect and repair' but Word does not start, so I can't have this option.

    I suspect I am missing some link between the old installation of windows and the new facility. I do not have the older Office CD so I can't reinstall. Did someone knows something I can check to try to get the Office to acknowledge that it is valid for this user. Betsy

    You are missing a lot of the associations. You need to reinstall your programs from the CD or the installable executables. I'm sorry that you do not have your Office CD-ROM, but you cannot reinstall Office without it. You can:

    1. try to contact Microsoft:
    How to replace lost, broken, or Missing Microsoft Software or Hardware - http://support.microsoft.com/default.aspx?scid=KB;en-us;326246

    2. buy a current version of Microsoft Office to your shop online/brick & mortar favorite.

    3. download/install the suite free OpenOffice to http://www.openoffice.org . MS - MVP - Elephant Boy computers - don't panic!

Maybe you are looking for