Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>SELECT DISTINCT Name FROM Table t WHERE NOT EXISTS(SELECT 1 FROM Table WHERE t.Name = Name AND Result = 'F' AND ',' || CsvOfTests || ',' LIKE '%,' || Test || ',%' ) </code></pre> <p>I would recommend using some unique value like auto-incremented id instead of the name here. If you want to have additional fields in the result set you can include them in your SELECT and GROUP BY field list or by using a join.</p> <p>CsvOfTests is the list of tests that you are interested of. I added commas to the beginning and the end of the CsvOfTests and Test in case name of one test is the substring of the name of some other test. However I have to say that I feel that the query would be much simpler and less hacky if you would put the tests into temporary table instead of csv string.</p> <p>If your input string separates tests by more than just a comma (like with a space after a comma you will need include those aswell). If it's more complicated than that then I guess I'd try REGEXP_LIKE or write my own function.</p> <p>Per request the query that counts passed subjects</p> <pre><code>SELECT DISTINCT Name FROM Table t WHERE LENGTH(CsvOfTests) - LENGTH(REPLACE(CsvOfTests, ',')) + 1 = ( SELECT COUNT(1) FROM Table WHERE t.Name = Name AND Result = 'P' AND ',' || CsvOfTests || ',' LIKE '%,' || Test || ',%' ) </code></pre> <p>Here <code>LENGTH(CsvOfTests) - LENGTH(REPLACE(CsvOfTests, ',')) + 1</code> counts the number of tests in your list. Then it justs counts how many of those tests the student has passed. Apparently there's also <a href="http://docs.oracle.com/cd/B28359_01/server.111/b28286/functions135.htm" rel="nofollow">REGEXP_COUNT</a> to do the same in 11g Release 1.</p> <p>After I reread and thought about your question, I understood that this was not exactly that you were asking for. The goal of this query more on the line of checking whether student has passed each subject (i.e. if you fail the exam the first time then you retake it and eventually pass).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload