Simple (I'm sure) SELECT FROM question - PIVOT

Hello

I have 2 paintings where one contains the IDS and TITLES of BOOKS and other information on the DVD that contains the images that we scan from the book. We have 2 types of DVD: 1 (Type C) containing images of high quality and the other (Type D), web quality images.

So I do not know how to make my query to display the following result
TABLE PUBLICATION

ID   |   TITLE
-----------------------------
1    |   LIFE Magazine
2    |   EARTH
3    |   The Economist
4    |   TIMES
5    |   ANIMALS


TABLE SERIEDVD

ID   |   ID.TITLE   |  TYPE   | DVD1(the first DVD of the serie)   | DVD2 (the last DVD of the serie)  
------------------------------------------------------------------------------------------------------------------------------------------------
1    |           1      |      C     |      182                                       |        216
2    |           1      |      D     |      678                                       |        679
3    |           2      |      C     |      1121                                      |        1245
4    |           2      |      D     |      700                                       |        703
5    |           3      |      C     |      576                                       |        613
6    |           3      |      D     |      236                                       |        256


WANTED RESULT (on one row. If I do a query, I have the result on 2 rows)

TITLE              |    TYPE C    First DVD  |  TYPE C Last DVD | TYPE D -  First DVD  | TYPE D Last DVD 

LIFE Magazine   |              182              |         216             |          678              |   679


If I do

Select P.TITLE, S.TYPE, S.DVD1, S.DVD2 FROM PUBLICATIONS P, SERIEDVD S where P.ID = S.ID.TITLE AND TITLE = 'Life Magazine'

I have this result:


TITLE              |    TYPE  |     First DVD  |    Last DVD | 

LIFE Magazine   |    C       |        182       |      216       |   
LIFE Magazine   |    D       |        678       |      679       |   


Thanks,


Roseline
Published by: Roseline September 30. 2009 04:43

Hi, Roseline,.

You need to Rotate your result of 2 rows on 1 row:

Select    P.TITLE
,       MIN (CASE WHEN s.type = 'C' THEN s.dvd1 END)     AS c_first
,       MIN (CASE WHEN s.type = 'C' THEN s.dvd2 END)     AS c_last
,       MIN (CASE WHEN s.type = 'D' THEN s.dvd1 END)     AS d_first
,       MIN (CASE WHEN s.type = 'D' THEN s.dvd2 END)     AS d_last
FROM       PUBLICATIONS     P
,       SERIEDVD     S
where       P.ID          = S.ID.TITLE
AND       TITLE      = 'Life Magazine'
GROUP BY  p.title;

Since there is only a value of s.dvd1 or s.dvd2 in each column, it does not matter if we use MIN or MAX.

Tags: Database

Similar Questions

  • Help: Configure the simple test sequence, operator selects particular test connects to the part of the teststand sequence file and then performs the test

    Hello

    I am very new to TestStand, please see the question below and give advice.

    I want to set up a simple test sequence.

    I want a message to popup on the screen that asks the operator what unit of 6 units (maximum 10) to test (i.e. There is say box of 6 to 10 s to select from).

    Then the sequence goes to the specific part of the sequence and performs the test on a unit that either has been selected.

    What is the best way to do it?

    I use pop-up message windows to do this? and if so what should I connect to the correct part of the sequence file?

    Pop-up message windows allow only 6 options to select from?

    Thank you

    Hello

    You can do this by using the method of message popup. You can ask the user what unit want to run message by inserting in the expression of the message in the message popup step parameters. Something like below

    "Enter the number of execution unit.

    1 Unit1

    2 unit 2

    .......

    10 Unit 10 "

    then check the 'Enable response text box"tab is different from the stage. When the user enters the unit number you can get the value entered by the user by inserting the below statement post expression of message popup step parameters

    Locals.String = Step.Result.Response

    Note: The string is a local variable to be set.

    Convert string to number and send that output to pass the expression you can use a sequence of call step to call the sequence according to which must be performed. (I hope your each unit will file separate sequence)

    I hope that this solves your problem. If you do not understand please let me know so that I can put a small example and send it to.

    See you soon,.

    Krishna

  • What privileges granted to select from all the PDB files

    Why the two selected does not return the same result? Or if you want the broader question - what privileges granted to select from all the PDB files.


    I want to leave common user that I created to select and see all of the synonyms of all PDB files.


    conn / as sysdba

    create user c##nir identified by c##nir container=all;

    grant connect,dba,resource to c##nir container=all;
    grant select on cdb_synonyms to c##nir container=all;

    select CON_ID  from cdb_synonyms  group by CON_ID;

      CON_ID
    ----------
      
    1
      
    4
      
    11
      
    10
      
    14
      
    5
      
    8
      
    13
      
    3
      
    7
      
    15
      
    6
      
    12
      
    9

    conn c
    ##nir/c##nir

    select CON_ID  from cdb_synonyms  group by CON_ID;

      CON_ID
    ----------
      
    1

    select CON_ID  from containers(dba_synonyms)  group by CON_ID
      
    *
    ERROR at line
    1:
    ORA-00942
    : table or view does not exist

    You must use the CONTAINER_DATA clause:

    ALTER USER ##nir set container_data = container c all = current;

    After running the above command, try to select again to cdb_synonyms and you will see the data of all containers.

    Read more in my Post of Blog

  • I use a PC and I used LR3. I'm a newcomer to LR, so patient with me! My problem is related to the import function. I have a photo library on an external hard drive. I slowly imported previews of the photos selected from the library in

    I use a PC and I used LR3. I'm a newcomer to LR, so patient with me! My problem is related to the import function.

    I have a photo library on an external hard drive. I've slowly been import previews of the photos selected from the library in my catalog, adding them during the import process - well. But now, I hit a problem. Another folder in my library contains several subfolders, each containing a number of photos (a mixture of RAW steals (naves) and jpg). I was importing found in my catalog each Subfile in turn, using the Add function, usually of the jpgs only from each Subfile. It works fine, until I reached a particular Subfile. For some reason when I try to import from it and select the secondary file as a Source, only the RAW (NEF) images appear in the preview pane (sorry, forgot the correct term for it!). I know that jpg files are in this auxiliary file on the external hard drive, because when I view its content in Windows, they are all there. But try as I can (choose the file under source, select the folder parent as a source, try to copy or move them, instead of adding them), nothing seems to work. Since they do not appear in the preview pane, I can't import them. It does appear that this a Subfile where the problem exists, but I don't see anything that is different from the others (names of files under all use the same structure - yyyy-mm-dd_custom name, and pictures in all subfolders are adopting the same denomination structure too - yyyy-mm-dd_sequential number_custom name.) NAVE/JPG. So what I am doing wrong? Any ideas please.

    It is possible that the images in this particular subfolder were taken in your camera in RAW + JPEG.  If so, you will need to go to preferences under the general tab and make sure the box "processing JPEG files files next to raw as separate photos" is checked.

    However, assuming that this is the case, there is really no reason to import the JPEG file if you already have the RAW file.

  • How to create a report based on the item selected from the list of selection?

    Hello

    I created a tables_LOV based on:

    Select table_name table_name user_tab_cols r, d

    where column_name like '% _type % '.

    Then I created a ListOfTables page element, display in a selection list and pointing to tables_LOV.

    I run the page, and I can choose the table I want in the drop-down list.

    How to create a report based on the selected element? (ex: select * from selected_table)

    Thanks in advance

    Salah

    Hi Salah,

    Allright, take a look at this page: http://apex.oracle.com/pls/apex/f?p=vincentdeelen:collection_report

    I think that simulates what you are trying to accomplish. I've implemented the simplest method I could think of.

    The report is based on a collection of apex. If you are not familiar with this, you should study the documentation: APEX_COLLECTION

    To recreate my example, you should:

    (1) create a report (interactive) on your collection

    SELECT *
       FROM APEX_collections
     WHERE collection_name = 'MY_COLLECTION'
    

    (2) create a selection list page_item for the tables that you want to display (in my case, this is called "P38_TABLES")

    (3) create a dynamic action that triggers on the evolution of your selection list page_item. Dynamic action must be a parade of PL/SQL procedure the following code:

    declare
      l_query varchar2(4000);
    begin
      l_query := 'select * from '||:P38_TABLES;
      if apex_collection.collection_exists
            ( p_collection_name => 'MY_COLLECTION' )
      then
        apex_collection.delete_collection
          ( p_collection_name => 'MY_COLLECTION' );
      end if;
    
      apex_collection.create_collection_from_query
        ( p_collection_name => 'MY_COLLECTION'
        , p_query           => l_query
        );
    end;
    

    Make sure that you add your page_item 'Page to send items' section.

    (4) add a real extra action that makes an update of the report area.

    Here are two photos describing the da:

    http://www.vincentdeelen.com/images/OTN/OTN_COLLECTION_REPORT_DA1.PNG

    http://www.vincentdeelen.com/images/OTN/OTN_COLLECTION_REPORT_DA2.PNG

    Good luck and greetings,

    Vincent

    http://vincentdeelen.blogspot.com

  • produce a series of numbers to select from the shortcomings of the ID column

    (1)

    Suppose I have a table t that contains lines like this:

    A AND B
    ---------- ----------
    2 4
    6 7

    I would like to use select to produce lines with numbers between a column and column B included
    for each line, like this:

    Select from t...

    2
    3
    4
    6
    7

    (2)

    Suppose I have the ID column that is lacking, I want to get the lowest < N > numbers available between the gaps.
    I did some research and I can find the range of gaps, but I can't get the numbers listed separately, therefore
    I ask the question (1). But is there a direct way for the list instead of going through beaches and the list.

    For example, I have the ID column that has

    2
    5
    6
    7
    9
    2000000

    I would get a select query that produces

    Select...

    3
    4
    8
    10
    11

    I have a way to get a list of 2 to 2000000, then less than what we need to get all the
    numbers of the gap, but who is not effective and may is short-term memory.

    PS: before I post on this group, I did some research already on "connect by", with recursive queries.

    PuraVidaOTN wrote:

    I would like to use select to produce lines with numbers between a column and column B included

    for each line, like this:

    Assuming that no duplicates in the table...

    with t as
    (
     select 2 c1,4 c2 from dual union all
     select 6 c1,7 c2 from dual
    )
    select c1,c2,c1+level-1 c
    from t
    connect by c1+level-1 <= c2
    and prior c1 = c1
    and prior c2 = c2
    and prior sys_guid() is not null;
    
    C1 C2 C
    -- -- -
     2  4 2
     2  4 3
     2  4 4
     6  7 6
     6  7 7 
    

    Suppose I have the ID column that is lacking, I want to get the lowest numbers between the gaps.
    I did some research and I can find the range of gaps, but I can't get the numbers listed separately, therefore
    I ask the question (1). But is there a direct way for the list instead of going through beaches and the list.

    I have a way to get a list of 2 to 2000000, then less than what we need to get all the
    numbers of the gap, but who is not effective and may is short-term memory.

    It's the best way in my opinion...

    Or rather less, you can try outer join...

    Published by: JAC on December 19, 2012 21:28

  • SELECT * FROM DUAL-&gt; Can this statement to make the quick health check?

    We have a product that will "SELECT * FROM DUAL" every 5 minutes. If there is no response, it sends an incident.

    My question is:-

    DUAL is a magic table in Oracle. So, without access to an actual table in oracle, can we take out of this statement
    before report us any problem on a database? In other words, this statement could be successful, but what are the chances
    that a query on a real table can fail due to limited resources?

    Thank you
    Delphine

    This statement could be successful, but what are the chances that a query on a real table can fail due to limited resources?

    Yes

  • Select * from tbl1 less select * from tbl2 is null

    Hi all
    I have 2 tables with the same 8 column, a column has the value zero from top to bottom.
    60 000 lines, tbl1 tbl2 has 70 000 lines.
    I need to see the 10,000 lines of tbl2 that are distinguished by the lines of tbl1.
    If I run select * from tbl1 intersect select * from tbl2, I get all the 60,000 tbl1 lines.

    However, if I run select * from tbl2 less select * from tbl1 I get no line?

    I can't understand why, can anyone help, please.

    Thank you
    Kowalsky

    Are you sure that it's really 10,000 TBL2 lines which are distinguished by a line any in TBL1? Instead of 10,000 additional rows in double?

    Justin

  • Select from another table, when the query returns no result

    Hello

    I have a question where I'm supposed to retrieve the address of an account id-based billing. However, the table of billing may not have an address. There is a table of addresses that always has an address for an account. If the billing address exists, it should be used, so I can't use the address table. Is it possible in a select statement to query to the billing address and if it does not exist, use the address table.

    SELECT * FROM accounts a, b billings WHERE a.accountid = b.accountid

    Any help will be greatly appreciated.

    Thank you.

    user10407139 wrote:
    Hello

    I have a question where I'm supposed to retrieve the address of an account id-based billing. However, the table of billing may not have an address. There is a table of addresses that always has an address for an account. If the billing address exists, it should be used, so I can't use the address table. Is it possible in a select statement to query to the billing address and if it does not exist, use the address table.

    SELECT * FROM accounts a, b billings WHERE a.accountid = b.accountid

    Any help will be greatly appreciated.

    I think you need to explain more clearly if

    -you only have a couple of "billing" columns which is empty and in this case, you want to use the columns from the table 'accounts '.

    - or you have a join with another table that doesn't return data, for example a foreign key "address_id" "billing" is zero and therefore the join to other tables 'address' will return all the data

    In the first case, you have already been provided with some examples here, how to use NVL or similar functions to achieve, even if the first post first evaluates the information of 'accounts' and if it is white using information from "billing". According to your description you need the other way around. The second post a subquery recursive useless in my opinion.

    In the latter case, you should probably use an "outer" join so that the data in your table "bills" are returned, even if the join to another table is not at all the lines.

    SELECT
    NVL(AD1.ADDRESS_ATTR1, AD2.ADDRESS_ATTR1) as ADDRESS_ATTR1,
    NVL(AD1.ADDRESS_ATTR2, AD2.ADDRESS_ATTR2) as ADDRESS_ATTR2,
    NVL(AD1.ADDRESS_STREET, AD2.ADDRESS_STREET) as ADDRESS_STREET,
    ...
    FROM accounts a
    INNER JOIN billings b
    ON a.accountid = b.accountid
    LEFT OUTER JOIN address ad1
    ON b.address_id = ad1.address_id
    INNER JOIN address ad2
    ON a.address_id = ad2.address_id;
    

    In this way you pick up the address stored in the "invoices" table, if it existed, otherwise you pick up the address assigned to the "accounts" table I used an inner for the second address join join because you said that the account always has an assigned address.

    Kind regards
    Randolf

    Oracle related blog stuff:
    http://Oracle-Randolf.blogspot.com/

    SQLTools ++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676 /.
    http://sourceforge.NET/projects/SQLT-pp/

  • Why don't I have easily select my questions open after the connection support?

    Why don't I have easily select my questions open after the connection support?

    When I connect support communities, I have still no clear idea where to find my support questions which remain open to check updates.

    Seems to me that this should be a great, distinct and separate button on the homepage of support after you have connected.  "My open issues Apple Community Support."

    Is this too much to ask?

    Steve

    1. Click / tap your username
    2. Click / tap 'manage subscriptions '.

  • Apple pencil will work as a simple pen on other iPads from Apple or iPhone?

    Apple pencil will work as a simple pen on other iPads from Apple or iPhone?

    N ° it only works with the iPad Pro.

  • Error: SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE TargetInstance ISA 'Win32_Processor' AND TargetInstance.LoadPercentage

    Original title: windows Vista SP2 is not start properly. Very, very slow and do not have access to open anything.

    I was able to boot into safe mode and view the event viewer, and that's what he said:

    ./root/CIMV2

        SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE TargetInstance ISA 'Win32_Processor' AND TargetInstance.LoadPercentage > 99
        0 x 80041003

    Hi Noomcy,

    1. don't you make changes before the show?

    This problem occurs if the WMI filter is accessible without the necessary permissions. To resolve this problem, we recommend that you run the script inthis article and check the result.

    See also Optimize Windows Vista for better performance

    Visit our Microsoft answers feedback Forum and let us know what you think.

  • SQLite Select * from table1 - cannot see last line

    Hello

    I did some testing with SQLite component on the Simulator and ran into a problem. When I try to retrieve the data from the database (storage works great... open the db to an observer and data file has been stored properly), I can't get the last line of the query. I have something in the sense of the following:

    try {
          Statement _statement = m_db.createStatement("SELECT * FROM TABLE1");
          _statement.prepare();
          _statement.execute();
          Cursor _cursor = _statement.getCursor();
          if (_cursor != null) {
    
            while (_cursor.next()){
                Row _row = (Row)_cursor.getRow();
                // Read row. For example:
                int idx1 = _row.getColumnIndex("id");
                int idx2 = _row.getColumnIndex("name");
    
                String _id           = _row.getString(idx1);
                String _name         = _row.getString(idx2);
            }
          }
          _statement.close();
          _cursor.close();
        } catch (Throwable e) {
          Dialog.alert("unable to get row data");
        }
    

    The first problem is that _cursor.next does not succeed, and the loop is not executed. If I change the code to force it to enter the loop (ie. cursor.first and run the .getPixel etc... in any case), I always get the LAST row, even when I use the position (1, 2, 3, 4... etc) function. It's pretty boring. I develop this 5.0 and testing with 9700 Simulator. Any ideas why I would see only the last row?

    Why the next file in the thropugh code above, I can't retrieve a row in the database?

    Note I tried dogin cursor.first ()... . Run the .GetPixel and the. next(), don't always gets me the line after line and the other always returns false. I do a select empty in the database, all lines should be there (checked the structure of data in another program... it is fine), no idea why it isn't here?

    Thanks in advance.

    Figured this out, the _statement.execute (); should not be there.

  • Select * from v$ PDB returning some lines of non - sys account DBA

    I am unable to find any documentation related to this privilege can benefit a common user in CBD root of database that allows the user to select from V$ PDB

    Server11:CPPPRD:Oracle: / u01/app > sqlplus C ##IMDBA - this user has a DBA role in the base of the root

    SQL * more: Production of the version 12.1.0.2.0 on Mon Sep 14 08:26:17 2015

    Copyright (c) 1982, 2014, Oracle. All rights reserved.

    Enter the password:

    Last successful login time: Fri Sep 11-2015 15:55:05-0600

    Connected to:

    Database Oracle 12 c Enterprise Edition Release 12.1.0.2.0 - 64 bit Production

    With the partitioning, OLAP, Advanced Analytics, Real Application Testing

    and Unified audit options

    SQL > select * from v$ PDB;

    no selected line

    SQL > exit

    Disconnected from the database Oracle 12 c Enterprise Edition Release 12.1.0.2.0 - 64 bit Production

    With the partitioning, OLAP, Advanced Analytics, Real Application Testing

    and Unified audit options

    Server11:CPPPRD:Oracle: / u01/app > sqlplus / as sysdba

    SQL * more: Production of the version 12.1.0.2.0 on Mon Sep 14 08:26:36 2015

    Copyright (c) 1982, 2014, Oracle. All rights reserved.

    Connected to:

    Database Oracle 12 c Enterprise Edition Release 12.1.0.2.0 - 64 bit Production

    With the partitioning, OLAP, Advanced Analytics, Real Application Testing

    and Unified audit options

    SQL > select name from v$ PDB;

    NAME

    ------------------------------

    PDB$ SEEDS

    APPPROD

    SQL > exit

    Disconnected from the database Oracle 12 c Enterprise Edition Release 12.1.0.2.0 - 64 bit Production

    With the partitioning, OLAP, Advanced Analytics, Real Application Testing

    and Unified audit options

    If you want that the common user will be able to view this data across all containers, you will need to use the container_data clause.

    Run through the user SYS to the CBD$ ROOT the following command:

    change user C ##IMDBA set container_data = container all = current

    BTW, you can also specify that C ##IMDBA will have the ability to view the data across all the container only for V$ PDB by running:

    change user ##IMDBA set container_data = all Molok sys.v_ C $pdbs = current

    And you can also check the settings of data container by selecting CDB_CONTAINER_DATA

    According to the Oracle doc:

    container_data_clause

    The container_data_clause allows the game and change CONTAINER_DATA to a common user attributes. Use of the FOR clause to indicate whether to set or change the default CONTAINER_DATA attribute or a specific object CONTAINER_DATA attribute. These attributes determine all of the containers (which can never exclude the root) whose data will be visible via CONTAINER_DATA objects to the common user specified when the current session is the root.

    Read more here:

    http://docs.Oracle.com/database/121/Admin/cdb_mon.htm#ADMIN13931

    http://docs.Oracle.com/database/121/SQLRF/statements_4003.htm#SQLRF01103

  • Is it possible to get the name of the tool selected from a script?

    Hello

    Is it possible to get the name of the tool currently selected from a script?

    I found this:

    https://forums.adobe.com/thread/579195

    https://forums.adobe.com/thread/2161923

    But these works in Photoshop... So, it is possible to get the name of the tool currently selected in InDesign? Is there a universal method that will work in other applications?

    I think that there is a toolBoxTools, app.toolBoxTools...

    P.

Maybe you are looking for