How to create this CSV in Sql query?

I have a order_detail table with the primary key order_detail_id and the foregin keys order_id and product_id. Also I have three other fields, A, B and C, to describe the nature of this order detail. A product_id can be existed on different order_id
but not in a single order_id (ie no duplicate product_id on a order). What I want the dataset to return is when passing the order_id, it could be single or multiple order_id, the query will give me the order_detail_id in comma seperate string if two or more
of the same product_id found on the multiple order_ids and the same value on the other three fields, A, B and C, ie I would like to group by all the order_detail_id in a single row if those conditions are met.  Thanks a million. 
Kahlua

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. 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. 
>> I have a order_detail table with the PRIMARY KEY order_detail_id and the foreign keys order_id and product_id. <<
WRONG. Order details are called weak entities in data modeling. They need a strong entity (the order) to exist. Therefore, the key has to include the order id as part of the PRIMARY KEY. There is no separate  “order_detail_id” in a correct model. 
>> Also I have three other fields [sic], A, B and C, to describe the nature of this order detail. A product_id can existed on different order_id but not in a single order_id (i.e. no duplicate product_id on a order). <<
Columns are not anything like fields. You need to learn basic terms. Here is what a polite person might have posted:
CREATE TABLE Orders
(order_nbr CHAR(15) NOT NULL PRIMARY KEY, 
CREATE TABLE Order_Details
(order_nbr CHAR(15) NOT NULL 
   REFERENCES Orders(order_nbr)
   ON DELETE CASCADE, 
 product_id CHAR(15) NOT NULL,
 PRIMARY KEY (order_nbr, product_id),
 order_qty INTEGER DEFAULT 1 NOT NULL
   CHECK (order_qty > 0), 
 -- special attributes
  alpha CHAR(5) NOT NULL,
  beta CHAR(5) NOT NULL,
  gamma CHAR(5) NOT NULL,
>> What I want the data set to return is when passing the order_id, it could be single or multiple order_id, the query will give me the order_detail_id in comma separate string if two or more of the same product_id found on the multiple order_ids and
the same value on the other three fields [sic], A, B and C, i.e. I would like to group by all the order_detail_id in a single row if those conditions are met. <<
WRONG! You want to violate First Normal Form (1NF) and do display formatting in the database! You have not ever read a book or had a class on RDBMS. CSV? No! 
Now, where is the sample data? More bad Netiquette! I have done this before; you can read the details at: 
http://www.tdan.com/view-perspectives/5343
It is a special case of a relational division. Since you did not post DDL, I will not post DML. 
--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

Similar Messages

  • How to get this output using sql query?

    Hi,
      How to get this output using sql query?
    Sno Name Age ADD Result
    1 Anil 23 delhi Pass
    2 Shruti 25 bangalor Pass
    3 Arun 21 delhi fail
    4 Sonu 23 pune Pass
    5 Roji 26 hydrabad fail
    6 Anil 28 delhi pass
    Output
    Sno Name Age ADD Result
    1 Anil 23 delhi pass
    28 delhi pass

    Hi Vamshi,
    Your query is not pretty clear.
    write the select query using Name = 'ANIL' in where condition and display the ouput using Control-break statements.
    Regards,
    Kannan

  • How to achieve this result using sql query?

    hello gurus,
    i have a table like this
    id    name
    1       a
    2       b
    3       c
    4       d
    5       e
    6       f
    7       g
    8       h
    9       i
    10     j
    11     k
    12     l
    13     m now my result should be like this
    id    name  id   name   id   name
    1       a     6       f      11     k
    2       b     7       g     12     l
    3       c     8       h     13     m
    4       d     9       i
    5       e     10      jhow to achieve it by sql query ?
    thanks and regards,
    friend
    Edited by: most wanted!!!! on Feb 22, 2012 5:55 AM

    hi,
    Did you mean this:
    with a as
    (select 1 id ,'a' name from dual
    union all select 2 id ,'b' name from dual
    union all select 3 id ,'c' name from dual
    union all select 4 id ,'d' name from dual
    union all select 5 id ,'e' name from dual
    union all select 6 id ,'f' name from dual
    union all select 7 id ,'g' name from dual
    union all select 8 id ,'h' name from dual
    union all select 9 id ,'i' name from dual
    union all select 10 id ,'j' name from dual
    union all select 11 id ,'k' name from dual
    union all select 12 id ,'l' name from dual
    union all select 13 id ,'m' name from dual
    select
      id_1
      ,name_1
      ,id_2
      ,name_2
      ,id_3
      ,name_3
    from
      select
        id id_1
        ,name name_1
        ,lead(id,5) over (order by id) id_2
        ,lead(name,5) over (order by id) name_2
        ,lead(id,10) over (order by id)  id_3
        ,lead(name,10) over (order by id) name_3
        ,rownum r
      from
        a
    where
      r <=5
    D_1                   NAME_1 ID_2                   NAME_2 ID_3                   NAME_3
    1                      a      6                      f      11                     k     
    2                      b      7                      g      12                     l     
    3                      c      8                      h      13                     m     
    4                      d      9                      i                                   
    5                      e      10                     j Regards,
    Peter

  • How to create graph based on sql query

    Hi all,
    I am using jdev 10.1.3.3
    My requirement is need to ctreate graph(pie chart) based on sql query ex: select count(empno) from emp group by deptno;
    and also i need to give link on graph. If i click 10 deptno part in pie chart only 10 deptno employee list need to display.
    Please help meeeeeee
    Thanks
    NR

    Hi,
    just non click able graph in ADF 10g using BI Graph: http://www.freewebalbum.com/blogs/faces/bjanko/blogs.jsp?blog=bjanko20070629162305
    regards,
    Branislav

  • [b]How to create this Custom Table on Custom Schema with foreign key [/b]

    This Custom Table is create in Custom Schema and Refers to Seeded Table in APPS schema
    1 create table test_dff (test_id number(15) primary key,
    2* invoice_id number(15) constraint ap_test_fk REFERENCES ap_invoices_all(invoice_id) ON DELETE CASCADE)
    SQL> /
    invoice_id number(15) constraint ap_test_fk REFERENCES ap_invoices_all(invoice_id) ON DELETE CASCADE
    ERROR at line 2:
    ORA-02270: no matching unique or primary key for this column-list
    How to create this Custom Table on Custom Schema
    thanks in advance

    hi prashant
    sorry for replying late, i have checked your query and it gives me no rows, but if i check for user_cons_columns it gives me no rows either in APPS Schema, but in AP schema it gives me
    SQL> SELECT * FROM user_cons_columns WHERE table_name = 'AP_INVOICES_ALL';
    OWNER CONSTRAINT_NAME TABLE_NAME
    COLUMN_NAME
    POSITION
    AP SYS_C008177 AP_INVOICES_ALL
    INVOICE_ID
    SQL> SELECT constraint_name, constraint_type FROM user_constraints WHERE table_name = 'AP_INVOICES_A
    LL';
    CONSTRAINT_NAME C
    SYS_C008177 C
    SYS_C008178 C
    SYS_C008179 C
    SYS_C008180 C
    SYS_C008181 C
    SYS_C008182 C
    SYS_C008183 C
    SYS_C008184 C
    SYS_C008185 C
    SYS_C008187 C
    SYS_C008189 C
    SYS_C008191 C
    and since this is a combination of Unique and Not Null Constraints , i am getting the same issue. do u have any solution to make the Detail table records to delete without using Alerts/DB Triggers?
    thanks for your time .
    abdul rahman

  • How to create a database in sql?

    My question is how to create a database in sql?

    entrant wrote:
    My question is how to create a database in sql?
    as Iam a beginner
    =================================================
    Learning how to look things up in the documentation is time well spent investing in your career.  To that end, you should drop everything else you are doing and do the following:
    Go to  docs.oracle.com.
    Locate the link for your Oracle product and version, and click on it.
    You are now at the entire documentation set for your selected Oracle product and version.
    BOOKMARK THAT LOCATION
    Spend a few minutes just getting familiar with what is available here. Take special note of the "books" and "search" tabs. Under the "books" tab (for 10.x) or the "Master Book List" link (for 11.x) you will find the complete documentation library.
    Spend a few minutes just getting familiar with what kind of documentation is available there by simply browsing the titles under the "Books" tab.
    Open the Reference Manual and spend a few minutes looking through the table of contents to get familiar with what kind of information is available there.
    Do the same with the SQL Reference Manual.
    Do the same with the Utilities manual.
    You don't have to read the above in depth.  They are reference manuals.  Just get familiar with what is there to be referenced. Ninety percent of the questions asked on this forum can be answered in less than 5 minutes by simply searching one of the above manuals.
    Then set yourself a plan to dig deeper.
    - *Read a chapter a day from the Concepts Manual*.
    - Take a look in your alert log.  One of the first things listed at startup is the initialization parms with non-default values. Read up on each one of them (listed in your alert log) in the Reference Manual.
    - Take a look at your listener.ora, tnsnames.ora, and sqlnet.ora files. Go to the Network Administrators manual and read up on everything you see in those files.
    - *When you have finished reading the Concepts Manual, do it again*.
    Give a man a fish and he eats for a day. Teach a man to fish and he eats for a lifetime.
    =================================

  • How to create a database in Sql server management studio

    how to create a database in Sql server management studio

    One method is to run the SQL statement below from a SSMS query window:
    CREATE DATABASE MyDatabase;
    You can also right-click on the Databases node in SSMS Object explorer and select New Database.
    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

  • How to create a csv file with NCS attributes?

    Hi
    i installed Cisco Prime NCS and trying to perform bulk update of device credentials with csv file.
    How to create a csv file with all required attributes?
    This is part of NCS online help talking about this topic:
    Bulk Update Devices—To update the device credentials in a bulk, select Bulk Update Devices from the Select a command drop-down list. The Bulk Update Devices page appears.You can choose a CSV file.
    Note        The CSV file contains a list of devices to be updated, one device per line. Each line is a comma separated list of device attributes. The first line describes the attributes included. The IP address attribute is mandatory.
    Bellow is test csv file i created but does not work:
    10.64.160.31,v2c,2,10,snmpcomm,ssh,zeus,password,password,enablepwd,enablepwd,60
    10.64.160.31,v2c,2,10,snmpcomm,ssh,zeus,password,password,enablepwd,enablepwd,60
    The error i am getting while importing this file:
    Missing mandatory field [ip_address] on header line:10.64.160.31,v2c,2,10,snmpcomm,ssh,zeus,password,password,enablepwd,enablepwd,60
    Assistance appreciated.

    It looks like the IP address field is incorrectly set.,
    It should be as follows
    {Device IP},{Device Subnet Mask}, etc etc
    so a practical example of the aboove could be (i dont know if this is completely correct after the IP address / Subnet Mask)
    10.64.160.31,255.255.255.0,v2c,2,10,snmpcomm,ssh,zeus,password,password,enablepwd,enablepwd,60
    below is a link to the documentation
    http://www.cisco.com/en/US/docs/wireless/ncs/1.0/configuration/guide/ctrlcfg.html#wp1840245
    HTH
    Darren

  • How to retreive this file in SQL*Plus

    If I upload files which name is KOREAN, name of files is invisible.
    I dont't know cause of this problem.
    How is keeping korean name of file from breaking?
    Also, answer how to retreive this file in SQL*Plus
    Thanks
    silverbell

    To access ifs data from SQL, you need to (officially) setup a 'user view'. Refer to the Java API documentation on how to do this. Once you have created the user view, then you may access this view using any SQL tool.

  • How to add a parameter to sql query in report

    Hi
    How to add a parameter to sql query in report.
    Parameter is from Visual studio
    example:
    select * from tab1 where dl=parameter???
    I have VS 2008 prof CR XI R2, mysql

    Hello,
    If you have this API available then you can modify the record selection formulae in code to add filtering:
              string recordSelectionFormula = "{T_INV_RPT_ADDR.IND_PROMUS} = {?P_PROMUS?} AND {T_INV_RPT_POINT.INVOICE_DATE} = DATE(2008, 05, 31) AND {T_INV_RPT_POINT.CHECKOUT_DATE} = date(2008, 04,29)";
                CrystalDecisions.CrystalReports.Engine.ReportDocument.RecordSelectionFormula = recordSelectionFormula;
    You have to format and follow the rules as in the Designer so not too much work to get this to work.
    CR for .NET may not have the ability so you will need to upgrade to a Developer version of Crystal Reports.
    Thank you
    Don

  • How to create CATALOG with MS SQL Server?

    Connection class has getCatalog(strCatalog) method. In order to use it, we must create CATALOG in Database?
    How to create CATALOG with MS SQL Server?
    Help me, please!!!

    You do not create these for any database, this is part of the Connection metadata.
    The Catalog is the third level of table-like database object qualification as in "Catalog.Schema.Table". For SQLServer the qualification scheme is "Database.Owner.Table" and I would be surprised if they reported anything for the current connections getCatalog() method call.
    What many people do is avoid table qualification altogether by setting the connection's context in a database proprietary manner and then keeping the SQL as clean as possible. For many ODBC and JDBC drivers this can be set in the configuration. For MS SQLServer you can also execute a "USE dbname" statement on the connection to avoid table qualification.

  • How to create snapshot portlet and snapshot query using server API

    How to create snapshot portlet and snapshot query using server API
    Regards
    Dheeraj

    Hi Sebastian,
    I have used the query and it is working fine. but, How could i include the headers of the query also in to the Excel Sheet.
    RehaanKhan. M
    see the method discussed here
    http://sqlblogcasts.com/blogs/madhivanan/archive/2008/10/10/export-to-excel-with-column-names.aspx
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to create a CSV file in java

    how to create a CSV file in java

    this is the code that I have used in a hp project:
    private static final String DELIMIT = ",";
    StringBuffer buf = new StringBuffer();
    public void addString(String str){
    buf.append(toEscapedStringLiteral(str.replaceAll(" ","").trim())).append(DELIMIT);
    public void sendFile( String strData ,
                                String strTitle,
                                String strContType,
                                HttpServletResponse res ) throws IOException {
              byte[] _filedata=strData.getBytes();
              res.setContentType( strContType );
              res.setHeader( "Content-Disposition", "attachment;filename="+ strTitle );     
                     DataOutputStream out = new DataOutputStream( res.getOutputStream() );
              out.write( _filedata, 0, _filedata.length );
              out.close();
    public void addStringWhithReturn(String str){
              buf.append(toEscapedStringLiteral(str.replaceAll(" ","").trim()));
              buf.append( "\n" );
    private String toEscapedStringLiteral( String charSeq ) {
              if ( null == charSeq ) {
                   charSeq = "";
              return "\"" + charSeq + "\"";
    ....hope its help
    kou

  • How to create a transport request with query and only with its structure.

    HI guru,
                how to create a transport request with query and only with its structure.transport request should not  include any other query items like ( variables, conditions...etc)
    thanks in advance.
    venkata

    Hi,
    Goto RSA1 and then Transport Connection -> In SAP Transports select Object Types-> Query Elements -> Then select Query->Give Technical name of the query and then select for transfer. In the right side you can choose the components which you wanted to transport.
    Regards,
    anil

  • How to create this Hieararchical Tree?

    Hi All,
    Please help me on this issue.
    I need DRILL DOWN functionality in forms. Im trying to Study / Create Hierarchi Tree Concept in Forms 6i, but couldn't able to manage /Understand how to create this. Please any one could help me. and im giving my scenario also here, whether it can support or not.
    Our routes having lot of terminals, like Our Bus travels from KENYA to SOUTH AFRICA passing TANZANIA,ZAMBIA,MALAWI,BOTSWANA countries. so i need the No of records to be dynamic i cant fix 10 records and scroll etc, Rather im trying to use Heirarchi Trees to achive this.
    My Table is like this.
    Table #1 Route_quotas
    Route_no,terminal_name,quota_station_from,quota_station_to,no_of_seats,seat_no_start_from,seat_no_ending
    Data is Like this:
    1,GNT,GNT,HYD,10,1,10
    1,GNT,GNT,VJA,40,11,50
    1,VJA,VJA,KDD,10,11,20
    1,VJA,VJA,HYD,30,21,50
    I need data to be displayed / functoned like this. If One select Route_no 1 in a List_item. Down to that i should show which terminals having quotas in this route. those are.
    GNT
    VJA
    Next ... If One selects this node like if one Expands GNT node the sub nodes should be like this having three coulmns (i.e quota_station_from,quota_station_to,no_of_seats columns)
    GNT HYD 10
    GNT VJA 40
    Next again.. if One select the first subnode it should give ...the seat Nos
    1,2,3,4,5,6,7,8,9,10 (please Omit the commas) and from there i should be able to select one seat_no and do some actions based on that. like RESERVE or ISSUE what ever i like. i need that Seat_no value.
    GNT
    ........GNT HYD 10
    ................ 1 2 3 4 5 6 7 8 9 10
    ........GNT VJA 40
    ................11 12 13 14 15....50
    VJA
    ........VJA KDD 10
    ................11 12 13 14 15 16 17 18 19 20
    ........VJA HYD 30
    ................21 22 23 24 ...... 50
    Thanks in advance.

    Rama,
    I would use nested PLSQL cursors to populate a record group and create the tree from there. This way you can also concatinate multiple values to show as a single name in a tree.
    Frank

Maybe you are looking for

  • Problems setting up 2nd email address

    Ok so I followed all the help instructions for setting up a second email address and all is fine. I can send test emails to my first account and I receive them within the same inbox. But then I hit two roadblocks: 1.) When I reply to the test message

  • How to return an error message from a zbapi that I have written

    Hello Friends I have written a simple ZBAPI that I have created. Here is the simple code that I have written which just inserts some value. How can I send information back using BAPIRETURN if the insertion was not successfull. Is it enough just to de

  • Font licensing for Air apps for iOS and Android

    Hi all, I'm trying to shift into the app design world after leaving academia and I'm currently working on a couple of 'portfolio' apps for some friends of mine. One thing I'm completely confused upon is Font Licensing and I'm really hoping someone ca

  • Relationship Between tables in ECC

    Hi Experts,        I have to generate one report which is belongs to Purchasing, Meterial and Delivery. I need to findout the relation between  MSEG and MBEW, these two tables are belongs to Meterial.     I found MATNR in both the tables but I found

  • Questions, Extreme begginer - Why wont this work.

    /* My Java Program Failing To Compile 2009 - CurrentDate() /* Importing */ import java.util.Scanner; import acm.graphics.*; import acm.program.*; class run {      public static void main(String args[]){      //Variables      Scanner ninjatext = new S