Number of comparison in the sem_match filter clause failed to Jena

Hello

I have the following query of sem_match, which has a filter clause to compare a variable with a number. It works in oracle very well; but, he failed in Jena.

Select interval_length

table (sem_match ('{? dose_interval RDF: type: Dose_Interval.? dose_interval: dose_interval_hourly? interval_length.}))

{filter (? interval_length < "6.0" ^ ^ xsd: Decimal)}'.

sem_models ('test'),

sem_rulebases ('owl2rl', 'testRules'),

sem_aliases (sem_alias (", 'http://www.example.com/test#')), null))

I run the query in Jena, but got the following error:

Exception in thread "main" java.lang.Error: problems compiling pending:

The operator * is not defined for the argument type java.lang.String, java.lang.String

Syntax on the token "6.0" error, * expected

Is this a bug or something wrong with my request? Thank you very much in advance.

Hong

Salvation Hong,

SEM_MATCH works well on JDBC. (Adapter Jena has performed SEM_MATCH on JDBC for many years.)

Now, I tried to compile your code and could not be compiled. After correction of some minor problems, I can compile it and run it without encountering errors.

public class TestHong

{

public static String szJdbcURL = "jdbc:oracle:thin:@localhost:1521:orcl";

public static String szUser = 'scott ';

public static String szPasswd = "Tiger."

public static String szModelName = "test";

public static oracle Oracle new = Oracle (szJdbcURL, szUser, szPasswd);

Public Shared Sub main (String [] szArgs) throws SQLException {}

Chart GraphOracleSem = new GraphOracleSem (oracle, szModelName);

Instruction stmt1d = null;

try {}

stmt1d = Oracle.GetConnection () .createStatement ();

String res = null;

String szQuery = "select interval_length ' +.

"table (sem_match ('{?})). dose_interval RDF: type: Dose_Interval. ? dose_interval: dose_interval_hourly? interval_length. " +

"filter (?). interval_length< \"6.0\"^^xsd:decimal)="" }',="" "="">

"sem_models ('test'), ' +.

"null," +

"sem_aliases (sem_alias (", 'http://www.example.com/test.owl')), "+".

"null));

System.out.println ("Request is" + szQuery);

ResultSet checkInterval = stmt1d.executeQuery (szQuery);

System.out.println ();

System.out.println ("* case 1: dose of the medication that is less than the recommended interval range *");

System.out.println ();

System.out.printf ("% - 25 s \n", "duration (hours)" ");

System.out.println ();

If (! checkInterval.isBeforeFirst ())

{System.out.println ("OOPS! In case 1, the medication dose intervals were not ");

System.out.println (); }

else {}

While (checkInterval.next ()) {}

RES = checkInterval.GetString ("interval_length");

System.out.printf ("" % - 25 s & \n, res);

}

}

System.out.println ();

}

Finally {stmt1d.close () ;}

}

}

This is the result I got against a model empty.

Query is select table interval_length (sem_match ('{? dose_interval RDF: type: Dose_Interval.? dose_interval: dose_interval_hourly? interval_length. filter (? interval_length < "6.0"^^xsd:decimal)="" }',="" sem_models('test'), ="" null,="" sem_aliases(sem_alias('',=""> http://www.example.com/test.owl')}), null))

* Case 1: meantime of dose of the medication that is less than the recommended interval

Duration (hours)

OOPS! In case 1, the medication dose intervals were not

It will be useful,

Zhe Wu

Tags: Database

Similar Questions

  • Why my version of Lightroom 5 has no moiré under the Radial filter tool?

    I was see screenshots in all directions 5 Lightroom that shows a number of tools under the Radial filter, including one for the memory. It's a big part of why I decided to join creative Cloud, but in my version of Lightroom 5, there is none of these tools. Anyone else has this same problem, or can anyone provide any input on what this could be? Thank you.

    Your image is set on an earlier Version of PV 2012 process. With PV 2010 or 2003, you will have access to the new PV 2012 controls...

  • How to remove the Order By clause

    How can I get rid of the Order By clause in the underlying SQL query? I created a simple hierarchy, but when I use the hierarchy in the analysis and then come down, the results show multiple occurrences of each child. For some reason, I was able to reduce the number of occurrences of each child by adding a saved filter.

    I was expecting this:

    Expected.jpg

    Instead, I got this:

    Actual.jpg

    The generated physical query looks like this:

    SET VARIABLE QUERY_SRC_CD = "report"; SELECT s_0, s_1, s_2, s_3, s_4 s_5, (FROM s_6)

    SELECT

    s_0 0,.

    CAST (NULL AS VARCHAR s_1 (1)).

    "Registration - College". «Dimensions of the inscription '.» "' Exercise ' s_2,.

    'All the colleges' s_3,.

    IDOF ("registration - College". «Hierarchies of the inscription '.» "College". ". ("' S_4 all Colleges").

    MOUNT s_5 (NULL AS DOUBLE),

    "Registration - College". "" Counties of schooling. "" Full-time student "s_6

    "REGISTRATION - College".

    UNION ALL

    SELECT

    1 s_0

    "Registration - College". «Dimensions of the inscription '.» "" Name of College "s_1,.

    "Registration - College". «Dimensions of the inscription '.» "' Exercise ' s_2,.

    'All the colleges' s_3,.

    IDOF ("registration - College". «Hierarchies of the inscription '.» "College". ". ("' S_4 all Colleges").

    IDOF ("registration - College". «Hierarchies of the inscription '.» "College". ". ("' S_5 College ').

    "Registration - College". "" Counties of schooling. "" Full-time student "s_6

    "REGISTRATION - College".

    WHERE

    ("Registration - College". «Dimensions of the inscription '.» ("' Exercise ' IN ('201213')) AND (IDOF ("registration - College". «Hierarchies of the inscription '.» "College". ". (("' Colleges ') (1))

    ) djm ORDER OF 1, 3 ASC NULLS LAST, 4 ASC NULLS FIRST, 5 ASC NULLS FIRST, 2 ASC NULLS FIRST, NULLS FIRST CSA 6

    EXTRACT FIRST 10000000 LINES ONLY

    HI mbengue,.

    Check the report you are running any column presentation sorted in the user interface (in which case the order by clause will creep into generated sqls Physics). Also, I think that its worth it to check the settings of the hierarchy you have configured and if the installation program for the calculation of the measured column (number of students in this case), has been done correctly.

    Kind regards

    Arko

  • How can I make the comparison of the two string one by one

    Hi all

    I'm new in labview and I'm stuck with the problem.

    I have a huge text with a different pressure values in different ports. My goal is to find the average value of the two ports and the dP and this value, I need to find the max value of dP.For that please see the attached VI. and see the structure 1st case of this home VI. This I already have.

    [I first hypothesis structure I compare the port 103 and 115]

    Now that I was for 2 ports and now I want to do a calculation for the comparison of the two ports but labview should do automatically, for reference, I have attached the text file.

    [Now, I want to compare 103 & 115 104 & 116, 105 & 117 automatically a]

    Please see the nd structure 2 for that. (in the first case structure I put table 1 d of search function to find the location of the port column but I manually write the "103" Port, now I want the labview automatically read the port of 103, on port 104 and calculate the average)

    He would be grateful if you can help me.

    I press the run button and push the button highlight to see execution. And I found something wrong.

    In the second element of research case structure function read the location of the column, but after identyfied the number of the column, the message not to the upper structure and the calculation has not started. Computing began when he reads the element and passes the final item column, then the calculation started...

  • Event: number of tracks of the same event?

    Hello world

    I'm working on a CCD acquire the system, and I developed the control software using a structure of the event.

    Each event controls a setting function for my system and place in fucnctions event timeout to get the status of my detector.

    Data acquisition is one of control events. Now, I need make several acquisition and save the data in a spreadsheet file, which must be called with the number of the iteration.

    For example the acquisition of 10, the acquisition event will be executed 10 times and save 10 files named: 1.csv, 2 csv...

    How can we build a counter showing the number of iterations of a single event (in the example the number of passages of the event "get data")?

    Thanks in advance

    Eugenio

    LabVIEW 2011

    Hi Eugenio,.

    Juice make a comparison for iteration 10 times. Use the value active signaling to ownership in the event of the acquisition. Try this and tell.

  • Update of the LR - where are the digits of the image and not classified in the view filter grid?

    Hello team Adobe,

    I've updated my LR to the most recent update (2015.7 / 1090788 build) that looks great, but... I'm having some trouble with the changes now affecting my work flow.

    1. where is the image numbering system in GridView?

    I watched each individual option in the 'library view Options' [COMMAND + J], but the number of image for the selected view is not available as an option.

    For example, the previous version would count the images in the grid, regardless of the selection filter applied (a star, five stars, not rated, etc...) which has been

    very useful for me. How can I get that back?

    2 - filtering options are all gone. I have to manually create each option filter manually?

    For example, to filter the images not class preset.

    Help, please! Thank you

    Known bug. Add your vote here: 2015.7 CC Lightroom: Badge numbers in the grid view not visible on the Sierra | Community customer Photoshop family

  • Reindexing a certain number of documents of Java custom filter

    I need assistance with the best way to present a number of documents from a Java filter.

    I have an event planned all night where I will call "scheduledSystemEvent" to run the custom filter.

    The filter will take away the dDocNames of content items, which must then be reindexed.

    How to run sucha mass updating/reindexing of the Java filter?

    Thank you very much for your help!

    Anya,

    These are actually two questions:

    (a) how to resubmit a group of documents?

    (b) how to do that (or whatever it is) a filter?

    Ad one) there is a RESUBMIT_FOR_CONVERSION of service http://docs.oracle.com/cd/E29542_01/doc.1111/e11011/core.htm#CSSRG2306 which takes a done, IMHO so all you need to do is provide a list of dIDs (or other identifiers) and somehow calling the function in a loop

    Ad b) If you're familiar with the implementation of the filter, I don't see why your code created in #a should not operate in a filter. However, who should be tested.

    Personally, I create a Java/RIDC normal application and schedule it to run as a process of batch of BONES. I see no benefit to do it in a filter - providing a context executing server-side or improve an existing feature.

  • How does the order by clause in oracle 10G?

    Hi This is my table called Master.I want to order by sno. so I run the below mentioned query.

    SNO DESC STIME, ETIME CCODE ADD SID

    11 11 11 1 10 s11

    1 1 s1 09:00 12:00 10

    2 2 s2 06:00 07:00 9

    3        3      S3        9:00       23:00                         0

    SELECT * FROM MASTER BY SNO

    SNO DESC STIME, ETIME CCODE ADD SID

    1 1 s1 09:00 12:00 10

    11      11         s11        11             1              10

    2         2         s2           6:00        7:00           9

    3         3         S3           09:00     23:00                        0

    but I had bad results. Help kindly me.i can't understand how the order by clause is fetching the record.

    Hello

    Most probably because that SNO is not digital, but a tank.

    If it contains a number onlly, try

    SELECT * FROM MASTER BY TO_NUMBER (SNO);

  • helps the load by clause of the query.

    guys I have a table like this
     create table fgbtrnh ( fgbtrnh_doc_code varchar2(9),
                                             fgbtrnh_trans_date date,
                                             fgbtrnh_trans_amt number(17,2),
                                             fgbtrnh_acct varchar2(6) ,
                                             fgbtrnh_fund_code varchar2(6),
                                             fgbtrnh_rucl_code varchar2(6) );
     
    with data like this.
       insert into fgbtrnh( fgbtrnh_doc_code,fgbtrnh_trans_date,fgbtrnh_trans_amt,fgbtrnh_acct,fgbtrnh_rucl_code,fgbtrnh_fund_code) values('J0005445','31-MAY-10','38491','6001','BD01','360098');
     insert into fgbtrnh( fgbtrnh_doc_code,fgbtrnh_trans_date,fgbtrnh_trans_amt,fgbtrnh_acct,fgbtrnh_rucl_code,fgbtrnh_fund_code) values('L0000005','01-JUL-08','38260','6001','BD01','360098');
     insert into fgbtrnh( fgbtrnh_doc_code,fgbtrnh_trans_date,fgbtrnh_trans_amt,fgbtrnh_acct,fgbtrnh_rucl_code,fgbtrnh_fund_code) values('L0000002','30-JUN-08','24425.29','6001','BD01','360125');
     insert into fgbtrnh( fgbtrnh_doc_code,fgbtrnh_trans_date,fgbtrnh_trans_amt,fgbtrnh_acct,fgbtrnh_rucl_code,fgbtrnh_fund_code) values('L0000002','30-JUN-08','48057.71','6001','BD01','360125');
     insert into fgbtrnh( fgbtrnh_doc_code,fgbtrnh_trans_date,fgbtrnh_trans_amt,fgbtrnh_acct,fgbtrnh_rucl_code,fgbtrnh_fund_code) values('M0000002','30-JUN-08','90','7200','BD01','360098');
    I would like to get a total run of these elements, so I tried something like that.
    select  f.fgbtrnh_doc_code,f.fgbtrnh_trans_date,f.fgbtrnh_trans_amt, sum(f.fgbtrnh_trans_amt)
    over
    (--partition by  f.fgbtrnh_doc_code
    order by fgbtrnh_trans_date desc  ROWS UNBOUNDED PRECEDING 
    --group by  f.fgbtrnh_doc_code
    )total
    From fgbtrnh f 
    where f.fgbtrnh_fund_code in ('360098', '360125')
    and f.fgbtrnh_rucl_code = 'BD01'
    and f.fgbtrnh_acct = '6001'
    order by  f.fgbtrnh_trans_date desc,  f.fgbtrnh_doc_code
    but I find myself with a result set as


    'FGBTRNH_DOC_CODE', 'FGBTRNH_TRANS_DATE', 'FGBTRNH_TRANS_AMT', 'TOTAL '.
    "J0005445", MAY 31, 10, 38491, 38491
    "L0000005", 1 JULY 08, 38260, 76751
    "L0000002", 30 JUNE 08, 24425.29, 101176.29
    "L0000002", 30 JUNE 08, 48057.71, 149234




    I want to thave the cumulative total to start at the bottom in the other Word is my total column I would like to finish with the top 149234
    so it should look something like this.





    'FGBTRNH_DOC_CODE', 'FGBTRNH_TRANS_DATE', 'FGBTRNH_TRANS_AMT', 'TOTAL '.
    "J0005445", MAY 31, 10, 38491, 149234
    "L0000005", 1 JULY 08, 38260, 110743
    "L0000002", 30 JUNE 08, 24425.29, 72483
    "L0000002", 30 JUNE 08, 48057.71, 48057.71


    I've tried everything and can't seem to make this work can someone please point me in the right direction.
    I would really appreciate the help.
    Thank you
    Miguel

    Hi, Miguel.

    mlov83 wrote:
    ... Also, if you order only the lines, you won't need the windowing clause ("UNBOUNDED PRECEDING LINES"); the default value ("RANGE UNBOUNDED PRECEDING") will have exactly what you want, so you n;' no need to say it.

    I don't really understand what you mean by that? But if I take a quick glance you say that all my lines will have to be unique, and then I won't have to use ("UNBOUNDED PRECEDING LINES")

    I think you have guessed it right.
    The ORDER BY clause Analytics don't have to result in a single ranking. There are good reasons for having a single oprdering, and there are good reasons for not having a single collation.
    I mean that If the analytical ORDER BY is unique, then you need not to give a widnowing clause, such as the "LINES OF UNBOUNDED'.

    Frank sorry if im asking some really stupid questions, but I have tried and tried to read and understand "partion by" and "over" works, but I'm not quite sure I understand yet.

    It's not stupid at all! Analytical functions can be very subtle and confusing.

    We will use a query based on the table scott.emp, which includes lines for each seveal deptno.

    -- Tell SQL*Plus to put a blank line between deptnos, just to make the output easier to read
    BREAK     ON deptno   SKIP 1     DUPLICATES
    
    SELECT       deptno
    ,       ename
    ,       sal
    ,       SUM (sal) OVER ( PARTITION BY  deptno
                                ORDER BY        sal
                      ROWS            UNBOUNDED PRECEDING
                    )     AS running_total
    FROM       scott.emp
    ORDER BY  deptno
    ,            sal          DESC
    ,       ename
    ;
    

    Output:

    `   DEPTNO ENAME             SAL RUNNING_TOTAL
    ---------- ---------- ---------- -------------
            10 KING             5000          8750
            10 CLARK            2450          3750
            10 MILLER           1300          1300
    
            20 FORD             3000         10875
            20 SCOTT            3000          7875
            20 JONES            2975          4875
            20 ADAMS            1100          1900
            20 SMITH             800           800
    
            30 BLAKE            2850          9400
            30 ALLEN            1600          6550
            30 TURNER           1500          4950
            30 MARTIN           1250          2200
            30 WARD             1250          3450
            30 JAMES             950           950
    

    PARTITION BY deptno"means to do a separate calculation for each distinct value of deptno. Lines with deptno = 10 effect the outcome on the lines where deptno = 20 or deptno = 30. Since there are 3 distinct values of deptno, there are 3 separate running totals.

    Note that the analytical ORDER BY clause translates into only a partial ranking. If there are two or more lines in the same deptno who have the same sal, look what can happen:
    {code}
    "DEPTNO ENAME SAL RUNNING_TOTAL.
    ---------- ---------- ---------- -------------
    ... 30 1500 4950 TURNER
    30 MARTIN 1250 2200
    1250 3450 DISTRICT 30
    30 JAMES 950 950
    {code}
    MARTIN and WARD are in the same partition (deptno = 30), and they both have the same sal (1250), so there is no reason why one of these lines would be considered 'before' it. When you use a windowing clause based on the LINES, as stated above, and there is equality for which line comes first (as there is equality between MARTIN and WARD), then one of the lines will arbitrarily be condidered before this one. In this example, it happened to chose MARTIN as the 2nd lowest sal, so running_total = 2200 (= 950 + 1250) on the line for MARTIN and running_total = 3450 (950 + 1250 + 1250) on the WARD line. There is no particular reason for this; It is completely arbitrary. I could do exactly the same question tomorrow or in 10 minutes and get running_total = 2200 to the rank of WARD and 3450 on MARTIN.
    However, it is no coincidence that MARTIN comes before WARD at the exit. the * request * ORDER BY clause (which has nothing to do with the analytical ORDER BY clause) ensures that, when two lines have the same deptno and sal, then the one with the earlier ename will come first.

    Now, what is the difference between a window based on the LINES and a window on the BEACH bnased?
    One difference is that, when a link appears in the ORDER BY clause, all rows with the same value of sal get the same value for SUM (sal):
    {code}
    SELECT DeptNo
    ename
    sal
    SUM (sal) over (PARTITION BY deptno
    ORDER BY sal
    ) AS running_total
    FROM scott.emp
    ORDER BY deptno
    sal DESC
    ename
    ;
    {code}
    Note that the only difference between the first query above, and this one is that it does not have an analytical windowing clause, then the default window, * RANGE * UNBOUNDED PRECEDING is used.
    Output:
    {code}
    "DEPTNO ENAME SAL RUNNING_TOTAL.
    ---------- ---------- ---------- -------------
    10 5000 8750 KING
    10 2450 3750 CLARK
    10 1300 1300 MILLER

    20 FORD 3000 10875
    20 3000 10875 SCOTT
    20 JONES 2975 4875
    20 1100 1900 ADAMS
    20 SMITH 800 800

    30 2850 9400 BLAKE
    30 1600 6550 ALLEN
    30 1500 4950 TURNER
    30 MARTIN 1250 3450
    1250 3450 DISTRICT 30
    30 JAMES 950 950
    {code}
    Again, look MARTIN and WARD near the end. They have both the sal of the soul, so they both have the same running_total = 3450 (= 950 + 1250 + 1250). This is often a desirable outcome, but in your case, it seems not to be. If you want running_totals MARTIN and WARD, then recesses you must use a window LINE, as we have done previously, or add a breakage in the ORDER BY clause, like this:
    {code}
    SELECT DeptNo
    ename
    sal
    SUM (sal) over (PARTITION BY deptno
    ORDER BY sal
    , ename DESC - changed (this is the only change)
    ) AS running_total
    FROM scott.emp
    ORDER BY deptno
    sal DESC
    ename
    ;
    {code}
    Output:
    {code}
    "DEPTNO ENAME SAL RUNNING_TOTAL.
    ---------- ---------- ---------- -------------
    10 5000 8750 KING
    10 2450 3750 CLARK
    10 1300 1300 MILLER

    20 FORD 3000 10875
    20 3000 7875 SCOTT
    20 JONES 2975 4875
    20 1100 1900 ADAMS
    20 SMITH 800 800

    30 2850 9400 BLAKE
    30 1600 6550 ALLEN
    30 1500 4950 TURNER
    30 MARTIN 1250 3450
    1250 2200 DISTRICT 30
    30 JAMES 950 950
    {code}

  • How do I display values skyrocket in the IR filter for the joined table columns?

    Hello

    I have a problem in the IR the query is based on a table, joined with other tables. I would like to provide users the ability to use IR filter search bar in the joined table columns. The problem facing on this filter, the Expression field, by pressing the arrow button displays values for the fields in the primary table, but not for fields that come from joined tables. Have you experienced this behavior in your reports? Is this normal?

    TIA

    Hello

    Correlated subqueries can improve performance - but it does not depend on the involved tables, the number of columns and the existence of indices. As far as I know, the optimizer has problems with them. You could try to explain the Plans on the two statements to verify that.

    In any case, I created a new test page with the SQL for IR:

    SELECT E.EMPNO,
    E.ENAME,
    D.DEPTNO,
    D.DNAME,
    E2.EMPNO "EMPNO2",
    E2.ENAME "ENAME2"
    FROM EMP E, EMP2 E2, DEPT D
    WHERE E.EMPNO = E2.EMPNO(+)
    AND E.DEPTNO = D.DEPTNO(+)
    AND E2.PRIMARY_EMPLOYEE(+) = 'Y'
    

    http://Apex.Oracle.com/pls/OTN/f?p=267:226

    As far as I can see, it works properly - except that if I do a filter on the ename column, when I try to create a second filter, drop-down lists ename all the values, while the other columns list only the available values after having applied the first filter. Which seems strange that the filters are applied as ANDS. But it does the same thing for other areas - IE, the field used in a filter is not filtered for the second filter - so I guess this is normal, but only a person in Apex could probably explain why it is so.

    Otherwise, everything seems to work as I expect and the above page works the same as my test page, which uses external joins http://apex.oracle.com/pls/otn/f?p=267:224

    Andy

  • Comparison of the tables to find items that differ - JS?

    I think I have my all wrong logic.

    I'm trying to compare two tables, with the result that I get a new array with the elements in the first, which do not appear in the second.

    Array1 - a, b, c and d, e

    table 2 - a, b, c

    new table must contain d, e

    THIS IS WHAT I'M TRYING...

    -Function to get graphics-

    function getGraphicsFunc()

    {

    -tests of graphics in library-

    MyLib = app.libraries.item var (0);

    the list of graphics in the library

    var libGraphicList = mylib.assets.everyItem () .name;

    Alert (libGraphicList);        <-- IT WORKS very WELL

    -Get a list of all the charts for CID on Pulse_OPI-

    var graphicFolder = the folder (basegraphpath + lastdigits + "/");

    var theGraphics = graphicFolder.getFiles ();

    var allGraphics = [];

    a content ID match files

    for (i = 0; i < theGraphics.length; i ++)

    {

    Assuming 8 sequence of numbers is a static number.

    You can also use grep to match 8-digit >

    If (theFiles [i]. Name.match(/^\d{8}/);

    If (theGraphics [i].name.indexOf (adCID) == 0)

    {

    allGraphics.push (theGraphics [i] .name);

    }

    }

    Alert (allGraphics);        <-- This WORKS FINE - the following comparison is the problem...

    Compare graphic tables to see which are NOT in the library

    var missingGraphics = [];

    for (j = 0; j < allGraphics.length; j ++)

    {

    if (toString (libGraphicList).indexOf(allGraphics[j]) is-1)

    {

    missingGraphics.push (allGraphics [j]);

    }

    }

    Alert (missingGraphics);        <-- THIS ALWAYS PRODUCES THE SAME "MISSING GRAPHICS" EVEN IF THEY ARE IN the INDL

    var graphicsFound = (missingGraphics.length)

    Alert ("On" + graphicsFound + "graphics found and imported into the library")

    }

    Many thanks in advance and Merry Christmas everyone...

    Which if statement says:

    If (String (libGraphicList). IndexOf(allGraphics[j]) is-1)

    or toString is a function you wrote, but not included?

    I would have probably used:

    If (libGraphicList.Join("|"). indexOf(allGraphics[j]) is-1)

    I thought of doing it this way. It is probably that the calculation of the loop by the string before the declaration and comparing with that.

    Dave

  • Concatenation of data with the GROUP BY clause

    Hi again!

    Following my previous thread...
    Re: Need help with RANK() on data ZERO

    I tried to apply the GROUP BY clause instead of preforming my query with RANK() to manage records NULL... I have a scenario where I also need to concatenate data from several lines.

    CREATE TABLE T_EMP (NUMBER OF EMP_NO, NAME VARCHAR2 (20));
    INSERT INTO T_EMP VALUES (1001, 'MARK');
    INSERT INTO T_EMP VALUES (1002, 'DAVID');
    INSERT INTO T_EMP VALUES (1003, "SHAUN");
    INSERT INTO T_EMP VALUES (1004, "JILL");

    CREATE TABLE T_EMP_DEPT (NUMBER OF EMP_NO, DEPT_NO NUMBER);
    INSERT INTO T_EMP_DEPT VALUES (1001, 10);
    INSERT INTO T_EMP_DEPT VALUES (1001, 20);
    INSERT INTO T_EMP_DEPT VALUES (1002, 10);
    INSERT INTO T_EMP_DEPT VALUES (1002, 20);
    INSERT INTO T_EMP_DEPT VALUES (1002, 30);
    INSERT INTO T_EMP_DEPT VALUES (1003, 20);
    INSERT INTO T_EMP_DEPT VALUES (1003, 30);
    INSERT INTO T_EMP_DEPT VALUES (1004, 10);

    CREATE TABLE T_EMP_VISITS (NUMBER OF EMP_NO, DEPT_NO NUMBER, VISITED DATE);
    INSERT INTO T_EMP_VISITS VALUES (1001, 10, 1 JAN 2009');
    INSERT INTO T_EMP_VISITS VALUES (1002, 10, 1 JAN 2009');
    INSERT INTO T_EMP_VISITS VALUES (1002, 30, 11 APR 2009');
    INSERT INTO T_EMP_VISITS VALUES (1003, 20, 3 MAY 2009');
    INSERT INTO T_EMP_VISITS VALUES (1003, 30: 14 FEB 2009');
    COMMIT;

    I have a T_EMP master table that stores the name and number of the emp. Each emp is required to visit some departments. This mapping is stored in the T_EMP_DEPT table. An employee can visit one or more departments. T_EMP_VISITS table stores the dates where the employee visited the services required. I need to view the report which should show when an employee all completed visits, which is the maximum date when it finished to visit all departments. If he did not visit any of the report should display date max, otherwise NULL. I was able to do using GROUP BY such proposed by Salim, but how do I show a list separated by commas of the services required for an employee in the same query.

    SELECT
    EMP_NO,
    NAME,
    MAX (DEPT_NO) KEEP (DENSE_RANK LAST ORDER BY VISITED) MAX_DEPT_NO,.
    MAX (VISITED) KEEP (DENSE_RANK LAST ORDER PER VISIT) VISITS_COMP
    DE)
    SELECT
    T_EMP. EMP_NO,
    NAME,
    T_EMP_DEPT. DEPT_NO,
    VISITED
    OF T_EMP
    LEFT OUTER JOIN T_EMP_DEPT
    ON T_EMP. EMP_NO = T_EMP_DEPT. EMP_NO
    LEFT OUTER JOIN T_EMP_VISITS
    ON T_EMP_DEPT. EMP_NO = T_EMP_VISITS. EMP_NO
    AND T_EMP_DEPT. DEPT_NO = T_EMP_VISITS. DEPT_NO)
    GROUP EMP_NO, NAME;

    Output
    EMP_NO NAME MAX_DEPT_NO VISITS_COMP
    1001 MARK 20
    1002 DAVID 20
    1003 SHAUN 20 3 MAY 09
    JILL 1004

    Power required
    EMP_NO NAME REQ_DEPTS MAX_DEPT_NO VISITS_COMP
    1001 MARC 20 10.20
    1002 DAVID 10,20,30 20
    1003 SHAUN 20,30 20 3 MAY 09
    JILL 10 1004

    Can we do this in a single query?

    Hello

    user512647 wrote:
    ... Sanjay
    The query you provided that stragg() use seems to work but my requirement is not in the result set. I don't know how to use stragg with
    MAX (DEPT_NO) KEEP (DENSE_RANK LAST ORDER BY VISITED) MAX_DEPT_NO,.
    MAX (VISITED) KEEP (DENSE_RANK LAST ORDER PER VISIT) VISITS_COMP
    I need more, these two columns these gives me the date when they have completed all visits. If they missed any Department then the result must be NULL in the VISITS_COMP field.

    Just add them to the SELECT clause:

    SELECT    t_emp.emp_no,
           name,
           STRAGG (t_emp_dept.dept_no)     AS deptno,
           MAX (t_emp_dept.dept_no) KEEP (DENSE_RANK LAST ORDER BY visited)
                                      AS max_dept_no,
           MAX (visited)                      AS visits_comp
    FROM             t_emp
    LEFT OUTER JOIN      t_emp_dept     ON   t_emp.emp_no     = t_emp_dept.emp_no
    LEFT OUTER JOIN      t_emp_visits     ON   t_emp_dept.emp_no     = t_emp_visits.emp_no
                                 AND  t_emp_dept.dept_no = t_emp_visits.dept_no
    GROUP BY  t_emp.emp_no
    ,            name
    ;
    

    The column called visit_comp is simply the last visited, regardless of how the employee visited departments.
    If you want to have the NULL value if the employee has not yet visited all 3 departments:

    ...       CASE
              WHEN  COUNT (DISTINCT t_emp_dept.dept_no) = 3
              THEN  MAX (visited)
           END                    AS visits_comp
    

    The 'magic number' 3 is the total number of departments.
    If you want to understand the correct value of that at the time of the execution of the query, replace the code literal 3 hard with a scalar subquery.

    Note that 'KEEP MAX (x) (DENSE_RANK OVER LAST SERVICE BY x)' (where the exact same column is used as an argument and that the ORDER BY column) is just "MAX (x)".

  • What's the point of having several columns in the ORDER BY clause?

    DB version: 10 gr 2

    When you use the ORDER BY clause, the lines are always sorted by the first column in the ORDER BY clause. So, what's the point of having several columns in the ORDER BY clause (I always see this in production codes)?

    For the below SQLs' schema SCOTT, result sets are always classified according to the first column ename. When I added use asc and desc of employment, does not change the result set.
    SQL> select * from emp order by ename;
    
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
    ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    20
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7839 KING       PRESIDENT            17-NOV-81       5000                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7934 MILLER     CLERK           7782 23-JAN-82       1300                    20
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7369 SMITH      CLERK           7902 17-DEC-80        800                    20
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
    
    14 rows selected.
    
    SQL> select * from emp order by ename, job;
    
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
    ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    20
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7839 KING       PRESIDENT            17-NOV-81       5000                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7934 MILLER     CLERK           7782 23-JAN-82       1300                    20
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7369 SMITH      CLERK           7902 17-DEC-80        800                    20
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
    
    14 rows selected.
    
    SQL>  select * from emp order by ename, job desc;
    
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
    ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    20
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7839 KING       PRESIDENT            17-NOV-81       5000                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7934 MILLER     CLERK           7782 23-JAN-82       1300                    20
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7369 SMITH      CLERK           7902 17-DEC-80        800                    20
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
    
    14 rows selected.

    Search in this example, you will see the difference

    SQL> create table test_order (name varchar2(10), surname varchar2(10), age number);
    
    Table created.
    
    SQL> insert into test_order values('Kamran','Agayev',26);
    
    1 row created.
    
    SQL> insert into test_order values('Kamran','Taghiyev',26);
    
    1 row created.
    
    SQL> insert into test_order values('John','Kevin',23);
    
    1 row created.
    
    SQL> select * from test_order;
    
    NAME       SURNAME           AGE
    ---------- ---------- ----------
    Kamran     Agayev             26
    Kamran     Taghiyev           26
    John       Kevin              23
    
    SQL> select * from test_order
      2  order by age;
    
    NAME       SURNAME           AGE
    ---------- ---------- ----------
    John       Kevin              23
    Kamran     Agayev             26
    Kamran     Taghiyev           26
    
    SQL> select * from test_order
      2  order by age asc, surname desc;
    
    NAME       SURNAME           AGE
    ---------- ---------- ----------
    John       Kevin              23
    Kamran     Taghiyev           26
    Kamran     Agayev             26
    
    SQL>
    

    When in the second query, I sorted out only for age, you saw it there two 26 years old Keita, there was first Agayev, then Taghiyev. But if I want to get the family names in descending order when there are two very old person, then I will add the second column in the order by clause

    - - - - - - - - - - - - - - - - - - - - -
    Kamran Agayev a. (10g OCP)
    http://kamranagayev.WordPress.com

  • A question about the analytical function used with the GROUP BY clause in SHORT

    Hi all

    I created the following table named myenterprise
    CITY       STOREID    MONTH_NAME TOTAL_SALES            
    ---------- ---------- ---------- ---------------------- 
    paris      id1        January    1000                   
    paris      id1        March      7000                   
    paris      id1        April      2000                   
    paris      id2        November   2000                   
    paris      id3        January    5000                   
    london     id4        Janaury    3000                   
    london     id4        August     6000                   
    london     id5        September  500                    
    london     id5        November   1000
    If I want to find which is the total sales by city? I'll run the following query
    SELECT city, SUM(total_sales) AS TOTAL_SALES_PER_CITY
    FROM myenterprise
    GROUP BY city
    ORDER BY city, TOTAL_SALES_PER_CITY;
    that works very well and produces the expected result, i.e.
    CITY       TOTAL_SALES_PER_CITY   
    ---------- ---------------------- 
    london     10500                  
    paris      17000            
    Now in one of my books SQL (Mastering Oracle SQL) I found another method by using the SUM, but this time as an analytic function. Here's what the method of the book suggests as an alternative to the problem:
    SELECT city, 
           SUM(SUM(total_sales)) OVER (PARTITION BY city) AS TOTAL_SALES_PER_CITY
    FROM myenterprise
    GROUP BY city
    ORDER BY city, TOTAL_SALES_PER_CITY;
    I know that the analytic functions are executed after the GROUP BY clause has been transformed completely and Unlike regular aggregate functions, they return their result for each line belonging to the partitions specified in the partition clause (if there is a defined partition clause).

    Now my problem is that I do not understand what we have to use two functions SUM? If we only use one only, i.e.
    SELECT city, 
           SUM(total_sales) OVER (PARTITION BY city) AS TOTAL_SALES_PER_CITY
    FROM myenterprise
    GROUP BY city
    ORDER BY city, TOTAL_SALES_PER_CITY;
    This generates the following error:
    Error starting at line 2 in command:
    SELECT city, 
           SUM(total_sales) OVER (PARTITION BY city) AS TOTAL_SALES_PER_CITY
    FROM myenterprise
    GROUP BY city
    ORDER BY city, TOTAL_SALES_PER_CITY
    Error at Command Line:2 Column:11
    Error report:
    SQL Error: ORA-00979: not a GROUP BY expression
    00979. 00000 -  "not a GROUP BY expression"
    *Cause:    
    *Action:
    The error is generated for the line 2 column 11 which is, for the expression SUM (total_sales), well it's true that total_sales does not appear in the GROUP BY clause, but this should not be a problem, it has been used in an analytical function, so it is evaluated after the GROUP BY clause.

    So here's my question:

    Why use SUM (SUM (total_sales)) instead of SUM (total_sales)?


    Thanks in advance!
    :)





    In case you are interested, that's my definition of the table:
    DROP TABLE myenterprise;
    CREATE TABLE myenterprise(
    city VARCHAR2(10), 
    storeid VARCHAR2(10),
    month_name VARCHAR2(10),
    total_sales NUMBER);
    
    INSERT INTO myenterprise(city, storeid, month_name, total_sales)
      VALUES ('paris', 'id1', 'January', 1000);
    INSERT INTO myenterprise(city, storeid, month_name, total_sales)
      VALUES ('paris', 'id1', 'March', 7000);
    INSERT INTO myenterprise(city, storeid, month_name, total_sales)
      VALUES ('paris', 'id1', 'April', 2000);
    INSERT INTO myenterprise(city, storeid, month_name, total_sales)
      VALUES ('paris', 'id2', 'November', 2000);
    INSERT INTO myenterprise(city, storeid, month_name, total_sales)
      VALUES ('paris', 'id3', 'January', 5000);
    INSERT INTO myenterprise(city, storeid, month_name, total_sales)
      VALUES ('london', 'id4', 'Janaury', 3000);
    INSERT INTO myenterprise(city, storeid, month_name, total_sales)
      VALUES ('london', 'id4', 'August', 6000);
    INSERT INTO myenterprise(city, storeid, month_name, total_sales)
      VALUES ('london', 'id5', 'September', 500);
    INSERT INTO myenterprise(city, storeid, month_name, total_sales)
      VALUES ('london', 'id5', 'November', 1000);
    Edited by: dariyoosh on April 9, 2009 04:51

    It is clear that thet Analytics is reduntant here...
    You can even use AVG or any analytic function...

    SQL> SELECT city,
      2         avg(SUM(total_sales)) OVER (PARTITION BY city) AS TOTAL_SALES_PER_CITY
      3  FROM myenterprise
      4  GROUP BY city
      5  ORDER BY city, TOTAL_SALES_PER_CITY;
    
    CITY       TOTAL_SALES_PER_CITY
    ---------- --------------------
    london                    10500
    paris                     17000
    
  • How to change the number of minutes for the exercise of the activity of the application

    How to change the number of minutes for the exercise of the activity of the application

    Hello

    It is not currently possible to change the goal of daily exercise.

    If you want to suggest that Apple consider adding this option, you can submit a request here:

    https://www.Apple.com/feedback/watch.html

Maybe you are looking for

  • Cell that contains the formula paste between spreadsheets

    How do I paste the value of a cell that contains the result of a spreadsheet formula has, in a worksheet cell B and still have the operation of the formula? OS 10.11.14, numbers 3.6.1.

  • Where is the "Home" tab on the top of the brwoser?

    I am running windows XP on your desktop and have updated to the latest version of Firefox. However, I can't find the tab "Home" single on top of the toolbar which can quickly take me to my home page.

  • No sound from the computer Windows XP

    Original title: reinstall his intergalactic max rated diglital I think that I remove my interqrated max sound on my computer and now I can't hear and sound

  • Addition of T60 fingerprint reader

    Hello I'll buy a T60 type used 1952wev, but this model does not have a fingerprint reader. Is it possible to replace the palmrest with a built-in fingerprint reader palmrest? Will it work? Thank you Gellert

  • Setting of power supply problems

    I use Windows Vista and have adjusted the power settings in the control panel so that the computer and the monitor may not turn off or go to sleep for four or five hours.  Even if I all the two will be stop after 20 minutes of inactivity even if musi