Match values of 2 columns with other rows

I want to compare the values of 2 columns with all rows in the sheet.
If there is a match I want to place a character in the next column, so I can filter on it
But I need to keep one row for each unique value. (match of 2 columns)

Hi,
I'm marking the reply as answer as there has been no update for a couple of days.
If you come back to find it doesn't work for you, please reply to us and unmark the answer.
Thanks
George Zhao
Forum Support
Come back and mark the replies as answers if they help and unmark them if they provide no help.
If you have any feedback on our support, please click "[email protected]"

Similar Messages

  • Can't compare a row with other rows within a table.. (many to many compare)

    Hi all..
    I am very new to PL/SQL..
    I need to travers through a table for comparing it's rows with in the table with other rows. For this I am trying to use bellow Pl/sql.
    create or replace compare()
    Declare
    VAR_HIT CHAR(1);
    SEARCH_RECORD_DATA UDB.table1%ROWTYPE;
    CANDIDATE_RECORD_DATA UDB.table1%ROWTYPE;
    CURSOR SEARCH_RECORDS_CURSOR IS SELECT * FROM UDB.table1 order by registration_id;
    CURSOR CANDIDATE_RECORDS_CURSOR IS SELECT * FROM UDB.table1 order by registration_id;
    BEGIN
    FOR SEARCH_RECORD_DATA IN SEARCH_RECORDS_CURSOR LOOP
    FOR CANDIDATE_RECORD_DATA IN CANDIDATE_RECORDS_CURSOR LOOP
    IF (CANDIDATE_RECORD_DATA.DECISION='P') THEN
    VAR_HIT:='y';
    IF(CANDIDATE_RECORD_DATA.FIRST_NAME!='unknown') AND (CANDIDATE_RECORD_DATA.FIRST_NAME!=SEARCH_RECORD_DATA.FIRST_NAME) THEN
    VAR_HIT:='n';
    ELSIF(CANDIDATE_RECORD_DATA.LAST_NAME!='unknown') AND (CANDIDATE_RECORD_DATA.LAST_NAME!=SEARCH_RECORD_DATA.LAST_NAME) THEN
    VAR_HIT:='n';
    ELSIF(CANDIDATE_RECORD_DATA.BIRTH_DATE!='unknown') AND (CANDIDATE_RECORD_DATA.BIRTH_DATE!=SEARCH_RECORD_DATA.BIRTH_DATE) THEN
    VAR_HIT:='n';
    ELSIF(CANDIDATE_RECORD_DATA.GENDER!='U') AND (CANDIDATE_RECORD_DATA.GENDER!=SEARCH_RECORD_DATA.GENDER) THEN
    VAR_HIT:='n';
    ELSIF(CANDIDATE_RECORD_DATA.FATHER_NAME!='unknown') AND (CANDIDATE_RECORD_DATA.FATHER_NAME!=SEARCH_RECORD_DATA.FATHER_NAME) THEN
    VAR_HIT:='n';
    ELSIF (CANDIDATE_RECORD_DATA.MOTHER_NAME!='unknown') AND (CANDIDATE_RECORD_DATA.MOTHER_NAME!=SEARCH_RECORD_DATA.MOTHER_NAME) THEN
    VAR_HIT:='n';
    END IF;
    IF(VAR_HIT='y') THEN
    INSERT INTO UDB.BIO_DI_HIT_RESULT(REGISTRATION_ID,SEARCH_ID,HIT_CANDIDATE_ID,SEARCH_DETAILS,CANDIDATE_DETAILS) VALUES (SEARCH_RECORD_DATA.REGISTRATION_ID,SEARCH_RECORD_DATA.EGM_NO,CANDIDATE_RECORD_DATA.EGM_NO,VAR_SEARCH_DETAILS,VAR_CANDIDATE_DETAILS);
    UPDATE UDB.BIO_RECORDS_DEMOGRAPHICS SET DECISION='D';
    END IF;
    END IF;
    END LOOP;
    commit;
    END LOOP;
    END;
    Outer loop is working fine (it is raversing throughout the table) (say for 8000 records 8000 times)
    But Enner loop is not working fine e.i. it's running just for 8000 times for 8000 records. while it should run more then 8000 time..
    Can any one help me..
    Is the way of using two cursor on one table for comparing each row of record is correct????????? :(

    Finally I come up with this:
    INSERT INTO UDB.BIO_DI_HIT_RESULT(REGISTRATION_ID,SEARCH_ID,HIT_CANDIDATE_ID,SEARCH_DETAILS,CANDIDATE_DETAILS)
    SELECT SEARCH.REGISTRATION_ID, SEARCH.Key_NO,CANDIDATE.Key_NO,
    'First name='||SEARCH.FIRST_NAME||',Last name='||SEARCH.LAST_NAME||',Birth date='||SEARCH.BIRTH_DATE||',Gender='||SEARCH.GENDER||',Fathers name='||SEARCH.FATHER_NAME||',Mother name='||SEARCH.MOTHER_NAME,
    'First name='||CANDIDATE.FIRST_NAME||',Last name='||CANDIDATE.LAST_NAME||',Birth date='||CANDIDATE.BIRTH_DATE||',Gender='||CANDIDATE.GENDER||',Fathers name='||CANDIDATE.FATHER_NAME||',Mother name='||CANDIDATE.MOTHER_NAME
    FROM UDB.BIO_RECORDS_DEMOGRAPHICS SEARCH,UDB.BIO_RECORDS_DEMOGRAPHICS CANDIDATE
    WHERE (SEARCH.FIRST_NAME!='unknown' OR SEARCH.LAST_NAME!='unknown' OR SEARCH.BIRTH_DATE!='unknown' OR SEARCH.GENDER!='unknown' OR SEARCH.FATHER_NAME!='unknown' OR SEARCH.MOTHER_NAME!='unknown')
    AND SEARCH.REGISTRATION_ID != CANDIDATE.REGISTRATION_ID
    AND SEARCH.REGISTRATION_ID < CANDIDATE.REGISTRATION_ID
    AND (SEARCH.FIRST_NAME='unknown' OR CANDIDATE.FIRST_NAME IN (SEARCH.FIRST_NAME,'unknown'))
    AND (SEARCH.LAST_NAME='unknown' OR CANDIDATE.LAST_NAME IN (SEARCH.LAST_NAME,'unknown'))
    AND (SEARCH.BIRTH_DATE='unknown' OR CANDIDATE.BIRTH_DATE IN (SEARCH.BIRTH_DATE,'unknown'))
    AND (SEARCH.GENDER='U' OR CANDIDATE.GENDER IN (SEARCH.GENDER,'U'))
    AND (SEARCH.BIRTH_DATE='unknown' OR CANDIDATE.BIRTH_DATE IN (SEARCH.BIRTH_DATE,'unknown'))
    AND (SEARCH.FATHER_NAME='unknown'OR CANDIDATE.FATHER_NAME IN (SEARCH.FATHER_NAME,'unknown'))
    AND (SEARCH.MOTHER_NAME='unknown' OR CANDIDATE.MOTHER_NAME IN (CANDIDATE.MOTHER_NAME,'unknown'))
    ORDER BY SEARCH.REGISTRATION_ID;
    Now it realy meet all my final table requirement.. I am happy.. :)
    But again last requirement is like..
    In the final BIO_DI_HIT_RESULT table I need to add one more column named as match_count
    This column will have values of total no. of exact match field (not unknown) for each records in the BIO_DI_HIT_RESULT.....
    One way of duing this is--
    Step1: I will use a cursor for traversing through each of the rows in BIO_DI_HIT_RESULT.
    Step 2: And based on count of matches in search_details(substring) and candiate_details(substring) I update each and every rows of the table.
    It will be very slow.. And for records like 2 million records.. I can't think of this idea. :(
    Sooooo,, Is there ANY BETTER WAY OF DOING THIS AS WELL.. BETTER MEANS FAST WAY.. :(
    Thanks in advance....
    Edited by: user13367608 on Jan 8, 2011 2:13 AM

  • Create a new column in a table that compares the value of one column with its previous value

    The DDL:
    DECLARE
    @T TABLE
    IDNO
    int,
    name
    varchar(40),
    [Date]
    datetime2,
    Price1
    float,
    Price2
    float
    DECLARE
    @K TABLE
    IDNO
    int,
    name
    varchar(40),
    [Date]
    datetime2,
    Price1
    float,
    Price2
    float
    INSERT
    INTO @T
    VALUES(22,'C_V_Harris','2014-01-02 10:23:49.0000000',
    23.335,      
    23.347)
    INSERT
    INTO @T
    VALUES(21,'C_V_Harris','2014-01-02 10:05:13.0000000',
    23.357,      
    23.369)
    INSERT
    INTO @T
    VALUES(20,'C_V_Harris','2014-01-02 09:56:15.0000000',
    23.364,      
    23.377)
    INSERT
    INTO @T
    VALUES(19,'C_V_Harris','2014-01-02 09:45:26.0000000',
    23.351,      
    23.367)
    INSERT
    INTO @T
    VALUES(18,'C_V_Harris','2014-01-02 09:43:20.0000000',
    23.380,      
    23.396)
    INSERT
    INTO @T
    VALUES(17,'C_V_Harris','2014-01-02 09:34:28.0000000',
    23.455,      
    23.468)
    INSERT
    INTO @T
    VALUES(16,'C_V_Harris','2014-01-02 09:30:37.0000000',
    23.474,      
    23.486)
    INSERT
    INTO @T
    VALUES(15,'C_V_Harris','2014-01-02 09:18:12.0000000',
    23.419,      
    23.431)
    INSERT
    INTO @T
    VALUES(14,'C_V_Harris','2014-01-02 09:16:06.0000000',
    23.360,      
    23.374)
    INSERT
    INTO @K
    SELECT
    ROW_NUMBER()
    OVER (ORDER
    by IDNO)
    AS RN,*
    FROM
    @T
    SELECT
    * FROM
    @K
    --not working:
    SELECT
    a.RN,a.Price2
    FROM
    @K a
    INNER
    JOIN @K
    b
    ON
    a.RN=b.RN-1
    WHERE
    a.Price2>b.Price2
    I need to create  a view with a column (say 'Comp' below) that compares the value of each row in Price2 with the previous Price2 row, and it is greater then +1, the
    same 0, and less -1.
    The processed table should be:
    IDNO
    name
    Date
    Price1
    Price2
    Comp
    22
    C_V_Harris
    1/2/2014 10:23:49
    23.335
    23.347
    0
    21
    C_V_Harris
    1/2/2014 10:05:13
    23.357
    23.369
    1
    20
    C_V_Harris
    1/2/2014 9:56:15
    23.364
    23.377
    1
    19
    C_V_Harris
    1/2/2014 9:45:26
    23.351
    23.367
    -1
    18
    C_V_Harris
    1/2/2014 9:43:20
    23.38
    23.396
    1
    17
    C_V_Harris
    1/2/2014 9:34:28
    23.455
    23.468
    1
    16
    C_V_Harris
    1/2/2014 9:30:37
    23.474
    23.486
    1
    15
    C_V_Harris
    1/2/2014 9:18:12
    23.419
    23.431
    -1
    14
    C_V_Harris
    1/2/2014 9:16:06
    23.36
    23.374
    -1
     How can I structure the statement to get (the most recent - order by date ) result for Comp?

    Satheesh Variath, I just had to make some corrections from your script to get the correct answer:
    CREATE
    VIEW vw_Comp
    AS
    SELECT
    TOP 1 t.IDNO,t.name,t.[Date],t.Price1,t.Price2,
    CASE
    WHEN t.Price2
    > LAG(Price2,1)
    OVER (PARTITION
    BY name
    ORDER BY IDNO) 
    THEN 1
    WHEN t.Price2
    < LAG(Price2,1)
    OVER (PARTITION
    BY name
    ORDER BY IDNo) 
    THEN -1
    ELSE 0
    END
    AS Comp
    FROM 
    @T t
    ORDER
    BY DATE
    DESC
    The adjustments: the selection of the most recent comparison (Top 1) and the use of the function LAG (instead of LEAD) to get the previous value of the column.

  • How can can i subtract the value of the column in each row ?

    I want to subtract  the value  of the column in each row if the row is not enough then continue to next row.
    For example 
    ID             QTY
    A               20
    B               40       
    C               60
    I want to update this table by subtract  the value  of the column (QTY) out 70 so the result i want will be 
    ID              QTY
    A                20 - 70 = -50 -->  0 this row will be updated to 0 and 50 will continue to next row   
    B                40 - 50  = -10 -->  0   this row will be updated to 0 and 10 will continue to next row
    C                60 - 10  = 50  -->  Stop loop
    How can i write the sql query for this operation , Thanks

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. You have no idea,
    do you? Temporal data should use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. What did you try on your own before posting? I will bet that you did nothing! You expect other people to do your job or homework for you. 
    >> I want to subtract the value of the column in each row if the row is not enough then continue to next row. <<
    This makes no sense. Rows have no ordering; that is a spreadsheet. There is no such thing as a generic “id” in RDBMS. And an identifier is not a sequence which would have an ordering. 
    CREATE TABLE Foobar
    (something_seq INTEGER NOT NULL PRIMARY KEY,
     onhand_qty INTEGER NOT NULL);
    Learn how to use the SUM()OVER() and LAG() aggregate functions, post what you tried for yourself and then we will help you. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • MS SQL - Add column with all rows being "0"

    Add column with all rows being "0"

    nevermind
    "lee" <[email protected]> wrote in message
    news:e3b5kt$mch$[email protected]..
    > Add column with all rows being "0"
    >
    >
    >

  • Merging two columns with muliple rows in Numbers '09

    I am trying to merge two columns each with 100 rows and related data. Column one is the street address and column two have office numbers. The final result would be one column with 100 rows with address and office numbers.
    Ed Carreon

    sanpanza wrote:
    I am trying to merge two columns each with 100 rows and related data. Column one is the street address and column two have office numbers. The final result would be one column with 100 rows with address and office numbers.
    Ed Carreon
    Hi Ed,
    Use the CONCATENATE() function.
    Street address in column D, Office number in Column E
    100 Smith ST            212
    Formula: =CONCATENATE(E," ",D)
    Result:
    212 100 Smith ST
    Note the formula has three arguments, the reference to column E, a text literal (" ") containing a single space, and a reference to column D.
    Regards,
    Barry

  • Best way to give a default value to a New Column with existing rows

    Adding some columns to SQL tables with existing data rows. There are also views created from these tables. The views are used in some report/query software so NULL values are not good. Interested in learning about the best way to set a default value. 
    These are the ways that I can think of
    1) ALTER TABLE using the DEFAULT to add the column and set the default value
    ++ Adds a constraint which is not terrible. Constraints are just not used much in this shop.
    2) ALTER TABLE to add the column then do an UPDATE statement to update the values
    ++ might be an issue for tables with millions of rows
    3) ALTER TABLE to add the column then use ISNULL in the CREATE VIEW

    It is a large table with 444 columns and max row size of 2268. 907k records took 1 minute 38 seconds to UPDATE the column. I have about 12 fields to add to this table and about 44 tables (not all this large of course) so it will take some time to
    UPDATE.  Although ... i just tried updating 3 columns in a single UPDATE and it took 1 minute 36 seconds. So If I did all 12 fields in a single UPDATE it would be about the same time as a single Field.  I will think about it.

  • Multiple columns with uneven rows

    Good Evening Everybody
    Could somebody advise me on the best solution to do the following.
    I have a csv file. The csv file is being read using "read from spreadsheet file" vi.
    The file contains multiple columns. The columns all have a different last row address. By this I mean that...say...the last row of column 1 is 5. Column 2 last row is 23, Column 3 last row is 12. etc. The file might look like the following...note...this is an example of a file only, and any implications can't be construed.
                Column1    Column2    Column3    Column4     Column5
    Row1        0               1                 2             3                 4
    Row2       12             23              13            34                 0
    Row3       11             44              23                               11
    Row4       34             55            
    Row5       21           
    Lets assume that the value(s) of interest are contained in columns 2,4 and 5. Therefore the values I want to extract would be 55, 34 and 11
    I can select the columns of interest fine, but am having difficulty working out how to find the last row for these columns
    Caveats:
    1. The number of columns changes
    2. Position of column in file changes address...never found in same address
    Does anybody know how I might be able to locate the last row in the column of my choosing.
    Thanks for any assistance.
    best regards
    Ray

    Hi Ray,
    load the csv as an array of strings. Empty cells will result in empty strings. So you can easily test each column for an empty item, which will mark the "End of Data"...
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • New Column Still Defaulting To Value From Deleted Column With Same Name

    This is strange. I had a managed metadata column called "Document Category" attached to multiple content types and set to a default value (different in each library). Then I deleted the column (all instances from libraries and references from
    content types as well), and created a new site column with the same name, but a Choice field instead. The libraries that had a default value for the original column, are still populating new documents using the original default value, and it's showing up as
    something like 88;#Hospital Correspondence|4b1e8da6-8653-492a-3e45e6c56c38 . The column is still a choice field, so I don't even know why it allows this value. Does anyone know why this is happening or how to fix it?

    Hi  Vince,
    Thank you very much for sharing your solution here. It  would be helpful for others who encounter similar issue.
    Thanks again,
    Eric
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support,
    contact [email protected]
    Eric Tao
    TechNet Community Support

  • Dragging one cell value(copy) across columns or across rows in ALV layout

    Hi friends,
    In bps layouts, data is displayed in ALV grid as interface. At plng folder level, can i incorporate excel feature like dragging one cell value across columns or across rows?  Simply if user enter one value in cell of ALV grid, that should be copied automatically across rows/columns while dragging?
    Second question, even i chose in layout builder excel as interface, that layout showed in plng folder as ALV grid layout. Why it happens so. I read documentation in UPSPM of that particular plng folder, it tells same thing(even if u choose excel, it will show in ALV only). So how can i get excel interface in plng folder?
    Regards,
    Kumar

    requested property is not possible at ALV layout level. Provided text document load facility to user. So user can directly load excel to plng folder.
    Issue resolved.

  • How to retrieve value of one column to other in Apex using Javascript

    Hi all,
    Can any one help me in solving this problem.
    How to send a value from one column to another column using javascript in Apex. I heard that we can use onChange().
    My requirement is,
    I have a column(Varchar2) in form where i need to enter a value and the data need to be sent to another column(Number) when i press apply changes.
    ex: if i enter a value say 1/3 or 1/4 or 1/3*1/6
    the result should be entered in the other column.
    Message was edited by:
    Raman

    Try something like
    html_GetElement('P1_ITEM2').value = eval(html_GetElement('P1_ITEM1').value);

  • Finding duplicate values in a column with different values in a different c

    I'm finding duplicate values in a column of my table:
    select ba.CLAIM_NUMBER from bsi_auto_vw ba
    group by ba.CLAIM_NUMBER
    having count(*) > 1;
    How can I modify this query to find duplicate values in that column where I DON'T have duplicate values in a different specific column in that table (the column CLMT_NO in my case can't have duplicates.)?

    Well, you can use analytics assuming you don't mind full scanning the table.....
    select
       count(owner) over (partition by object_type),    
       count(object_type) over (partition by owner)
    from all_objects;You just need to intelligently (i didn't here) find your "window" (partition clause) to sort the data over, then make use of that (the analytics would be in a nested SQL and you'd then evaluate it in outside).
    Should be applicable if i understand what you're after.
    If you post some sample data we can mock up a SQL statement for you (if what i tried to convey wasn't understandable).

  • How to get value in previous column and another row from Matrix with Custom Code?

    I want to calculate the value of tb_Open and tb_Close. I try to use custom code for calculate them. tb_close is correct but tb_Open is not correct that show value = 0 .
    This is example report:
    * I have 2 Dataset , Dataset1 is all data for show in my report. Dataset2 is only first Open for first month
    * First value of Open is item field in Dataset2 and this value only for first month (january). But for other month Open value get from Close in previous month.
    Detail for Red number:
    1. tb_Open -> tb_Close in previous month but first month from item field in Dataset2
    expression =FormatNumber(Code.GetOpening(Fields!month.Value,First(Fields!open.Value, "Dataset2")))
    2. tb_TOTAL1 group on item_part = 1
    expression =FormatNumber(Sum(CDbl(Fields!budget.Value)))
    3. tb_TOTAL2 group on item_part = 3 or item_part = 4
    expression =FormatNumber(Sum(CDbl(Fields!budget.Value)) + ReportItems!tb_TOTAL1.Value )
    4. tb_TOTAL3 group on item_part = 2
    expression =FormatNumber(Sum(CDbl(Fields!budget.Value)) - ReportItems!tb_TOTAL2 .Value)
    5. tb_Close -> calculate from tb_TOTAL3 - tb_Open
    expression =FormatNumber(Code.GetClosing(ReportItems!tb_TOTAL3.Value,ReportItems!tb_Open.Value))
    My custom code:
    Dim Shared prev_close As Double
    Dim Shared now_close As Double
    Dim Shared now_open As Double
    Public Function GetClosing(TOTAL3 as Double,NowOpening as Double)
        now_close = TOTAL3 + NowOpening
        prev_close = now_close
        Return now_close
    End Function
    Public Function GetOpening(Month as String,NowOpen as Double)
        If Month = "1" Then
            now_open = NowOpen
        Else    
            now_open = prev_close
        End If
        Return now_open
    End Function
    Thanks alot for your help!
    Regards
    Panda A

    Looks okay to me.
    Perhaps the variables should be declared as public (?)

  • I have read 118 files (from a directory) each with 2088 data and put them into a 2 D array with 2cols and 246384row, I want to have aeach file on a separate columns with 2088 rows

    I have read 118 files from a directory using the list.vi. Each file has 2 cols with 2088rows. Now I have the data in a 2 D array with 2cols and 246384rows (118files * 2088rows). However I want to put each file in the same array but each file in separate columns. then I would have 236 columns (2cols for each of the 118 files) by 2088 rows. thank you very much in advance.

    Hiya,
    here's a couple of .vi's that might help out. I've taken a minimum manipulation approach by using replace array subset, and I'm not bothering to strip out the 1D array before inserting it. Instead I flip the array of filenames, and from this fill in the end 2-D array from the right, overwriting the column that will eventually become the "X" data values (same for each file) and appear on the right.
    The second .vi is a sub.vi I posted elsewhere on the discussion group to get the number of lines in a file. If you're sure that you know the number of data points is always going to be 2088, then replace this sub vi with a constant to speed up the program. (by about 2 seconds!)
    I've also updated the .vi to work as a sub.vi if you wa
    nt it to, complete with error handling.
    Hope this helps.
    S.
    // it takes almost no time to rate an answer
    Attachments:
    read_files_updated.vi ‏81 KB
    Num_Lines_in_File.vi ‏62 KB

  • How to update the value of a column when a row is deleted

    Hi,
    My requirement is basically i have a table .Below is a sample data along with sample data
    Column A Column B ColumnC
    1 SAM 0
    2 RAM 0
    Now if i run a delete statement saying
    delete from Table where ColumnA =1 then i want to see the value of ColumnC to be updated as 1.The row shouldnt be deleted however the value of ColumnC should be changed to 1.
    Can someone please help me with any suggestions? I can create a trigger but i havent worked with triggers so not sure on how to use it.
    Please let me know if i am unclear or if you need any details.
    Thanks

    As I understand what you need is an INSTEAD OF DELETE trigger like below
    CREATE TRIGGER Trg_TableName
    ON TableName
    INSTEAD OF DELETE
    AS
    BEGIN
    UPDATE t
    SET ColumnC = 1
    FROM TableName t
    WHERE EXISTS (SELECT 1
    FROM DELETED
    WHERE ColumnA = t.ColumnA
    END
    this will set ColumnC to 1 and will not do an actual delete of the row.
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

Maybe you are looking for