How to achieve the querys in one statement

<p>
Hi,everyone:
I have a table:
create table my_cube
(model char(10), theyear char(10), color char(10), units_sold smallint);
</p>
<p>
To list the unit-sold percentage of the 'chevy' model in 1990, i write:
</p>
<p>
select 1990, 'Chevy', round(( (select sum(units_sold) from my_cube where model='Chevy' and theyear=1990)/(select sum(units_sold) from my_cube where theyear=1990) )*100, 2) from dual;
</p>
<p>
But i'm wondering is that possible to list all the unit-sold percentage of all models in every year in one statement? Could anyone help me. Thanks.
</p>
<p>
Here are some values for test:
insert into my_cube values('Chevy', 1990, 'Red', 5);
insert into my_cube values('Chevy', 1990, 'White', 87);
insert into my_cube values('Chevy', 1990, 'Blue', 12);
insert into my_cube values('Chevy', 1991, 'Red', 54);
insert into my_cube values('Chevy', 1991, 'White', 95);
insert into my_cube values('Chevy', 1991, 'Blue', 19);
insert into my_cube values('Chevy', 1992, 'Red', 31);
insert into my_cube values('Chevy', 1992, 'White', 54);
insert into my_cube values('Chevy', 1992, 'Blue', 11);
insert into my_cube values('Ford', 1990, 'Red', 64);
insert into my_cube values('Ford', 1990, 'White', 62);
insert into my_cube values('Ford', 1990, 'Blue', 13);
</p>

First of all, don't use CHAR. Use VARCHAR2. Save yourself some headaches.
Make the year column a number, and be careful about the column name MODEL. It's a reserved word.
Aside from the above solution, you could also use the handy ratio_to_report function:
SQL> select m_year, m_model
  2        ,sum(m_units_sold)
  3        ,ratio_to_report(sum(m_units_sold)) over (partition by m_year) r
  4  from   my_cube
  5  group  by m_year, m_model
  6  ;
              M_YEAR M_MODEL       SUM(M_UNITS_SOLD)                    R
                1990 Chevy                       104 .4279835390946502058
                1990 Ford                        139 .5720164609053497942
                1991 Chevy                       168                    1
                1992 Chevy                        96                    1

Similar Messages

  • How to achieve the results by Query ??

    Hello Guys,
    I have couple tables which I need to join to get the result....This is what is in the tables...
    CList Table
    CID, Name
    A, ABC
    B,CDE
    C,JFK
    JList Table
    JID, Name
    1, Something
    2, Another
    3, Else
    4, Should be something
    JOb_2_Courses
    JobID, CourseID
    1,A
    1,B
    2,C
    Employee Table
    EID, Job_ID
    1A, 1
    2A,1
    3B,1
    2C,2
    23D,3
    CStatus Table
    StatusID, Desc
    1,Completed
    2,Pending Approval
    3,Declined
    4,Scheduled
    5,Register
    Now user can only register the course which are related with their job....NO course else.....
    When they register it is moved to temp_course_registration and then once completed to COURSE_HISTORY
    For Example : So Employee : 1A will see two courses to register A and B...
    Say he registers A....it makes an entry in temp_course_registration table with the course id, employeeid and date....
    With further steps once that status is updated to '1'.....the course is deleted from temp_course_registration and is moved to course_history........
    Now to show to the user...I need to include all my tables in the query and on the basis of status, show necessary things to the user....
    Output :
    Course_ID, Status.............
    Say if they completed the course will come from course_history, if in the process will come from temp_course_registration.....if nothing is in the tables for the specific employee...this means status is '5' and they need to register everything...
    Can someone let me know, how to achieve the results....
    Thanks,
    Harsimrat

    Hello
    I'm off home now so I can't look at the query, but for future reference, if you want to improve your chances of getting help, you need to provide simple create table statements, and test data to go with it. I've done that with what you provided and hopefully someone else will be able to help. Also, you were asked if you could provide this in your other thread...
    CREATE TABLE CList(CID varchar2(1), Name varchar2(3))
    insert into clist values('A', 'ABC');
    insert into clist values('B','CDE');
    insert into clist values('C','JFK');
    CREATE TABLE JList(JID number, Name varchar2(30))
    insert into jlist values(1, 'Something');
    insert into jlist values(2, 'Another');
    insert into jlist values(3, 'Else');
    insert into jlist values(4, 'Should be something');
    CREATE TABLE JOb_2_Courses(JobID number, CourseID varchar2(1))
    insert into job_2_courses VALUES(1,'A');
    insert into job_2_courses VALUES(1,'B');
    insert into job_2_courses VALUES(2,'C');
    CREATE TABLE Employee (EID varchar2(3), Job_ID number)
    INSERT INTO employee VALUES('1A', 1);
    INSERT INTO employee VALUES('2A',1);
    INSERT INTO employee VALUES('3B',1);
    INSERT INTO employee VALUES('2C',2);
    INSERT INTO employee VALUES('23D',3);
    CREATE TABLE CStatus(StatusID number, Descr varchar2(30))
    insert into cstatus values(1,'Completed');
    insert into cstatus values(2,'Pending Approval');
    insert into cstatus values(3,'Declined');
    insert into cstatus values(4,'Scheduled');
    insert into cstatus values(5,'Register');HTH
    David

  • How to achieve the from and to date range in report builder 3.

    I AM TRYING TO CREATE ONE REPORT FROM REPORT BUILDER 3.
    WHERE I AM UNABLE TO DEFINE THE DATE RANGE.
    HOW TO ACHIEVE THE DATE RANGE IN REPORT BUILDER.
    NEED FROM DATE AND TO DATE FILTER IN REPORT BUILDER FOR PK DATE.

    Hi Ganesh,
    According to your description, you create a report in Report Builder 3.0, and create two parameters FromDate and EndDate, now you want to use the parameters in your MDX query, right?
    If in this case, here is a sample query for your reference.
    select
    {[Measures].[Internet Sales Amount]
    } on columns,
    {[Date].[Date].members} on rows
    from(
    select
    STRTOMEMBER("[Date].[Date].&["+@StartDate+"]"):STRTOMEMBER("[Date].[Date].&["+@EndDate+"]")
    ) on columns
    from [Adventure Works]
    Reference:STRTOMEMBER
    Regards,
    Charlie Liao
    TechNet Community Support

  • How to read the content in one node of XML in Java? Pls help

    My dear brothers,
    I am a newbie of XML, I have a exercise which is creating a Tree View from XML file. But the trouble is I do not know how to read the content in one node of XML file. I decide to use the algorithm as following:
    1. Create a GUI form which gives the ability for user to choose a XML file (ok)
    2. Load XML and return the file (ok)
    3. Read the file from node to node to create the node in Tree View (?!)
    Please help me, and if you are enough kind, please give me an small example to easy understand. Thanks in advance.
    Hoang Yen Binh

    I hope this one helps you.
         <ABC Type="ProductBased" ProdName="One" Location="India">
              <CEO>Raj</CEO>
              <Finance>Vikram</Finance>
              <HR>Karthik</HR>
              <Technical>Satish</Technical>
         </ABC>
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.NamedNodeMap;
    import org.w3c.dom.Attr;
    import org.w3c.dom.NodeList;
    import org.w3c.dom.Node;
    import org.w3c.dom.DOMException;
    import javax.xml.parsers.ParserConfigurationException;
    import org.xml.sax.SAXException;
    import java.io.File;
    import java.io.IOException;
    public class XmlReading {
         Document doc;
         Element element;
         public static void main(String[] args) throws Exception{
              XmlReading xr = new XmlReading();
              xr.getXmlParser(args);
         public void getXmlParser(String[] args) {
              DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                   if(args.length != 1) {
                        System.err.println("Argument Required");
              try {
                   DocumentBuilder builder = factory.newDocumentBuilder();
                   doc = builder.parse(new File(args[0]));
              }catch(ParserConfigurationException e1) {
              }catch(SAXException e2) {
              }catch(IOException e3) {
              getAttributes();
         public void getAttributes() {
              // Retrive the entire Document from the Dom Tree
              element = doc.getDocumentElement();
    //          System.out.println(element);
              NamedNodeMap attrs = element.getAttributes();
              // Get number of attributes in the element
         int numAttrs = attrs.getLength();
         // Process each attribute
              for (int i=0; i<numAttrs; i++) {
                   Node node = attrs.item(i);
                   // Get attribute name and value
                   String attrName = node.getNodeName();
                   String attrValue = node.getNodeValue();
                   System.out.println(attrName + ": " + attrValue);
              String s1 = element.getTagName();
              System.out.println(s1);
              // To get all the elements in a DOM Tree
              NodeList nl1 = element.getElementsByTagName("*");
              int i2 = nl1.getLength();
              System.out.println(i2);
              for(int i=0; i<i2; i++) {
                   System.out.println(nl1.item(i) + "\n");
    }

  • How to pack the More than one sales order delivery qty in one packing

    Hi Folks,
    How to pack the more than one sales order quantity combinely during packing?
    Thansk in advance and points wil be rewarded for the reply.
    Best Regards
    Srinivas

    Packing is done during Delivery.
    In Sales order also Packing function is available but as a Packing proposal.
    So actual packing is done in Delivery.
    When you process several sales orders together, the sales order items having same Ship-to-party, Shipping point, Route, Delivery due date & Incoterm are combined into one Delivery in the standard system.
    In the delivery overview screen,do the picking by subsequent function rom the menu bar, you will get a button "PACK", click on this system will take you to the packing screen.
    In the packing screen, give the packaging mterial number, select the materials to be packed, select the packaging material also and the click on the "PACK" button.

  • After the new project by importing PPT release, how to achieve the release of the demo mode SWF, but not now only Click to continue?

    After the new project by importing PPT release, how to achieve the release of the demo mode SWF, but not now only Click to continue?
    Note:Captivate 5.5
    Thks

    通过导入PPT新建的项目发布后,如何实现发布演示模式的SWF(自动播放),而不是交互模式的SWF(只能点击才能继续)?

  • How to remove the Char.from one Operating Concern

    Hi Guys,
    How to remove the Char. from one Operating Concern.
    I have created one Char. (WWDOC) and moved to Operating Concern (OOCC). Operating Concern is in red status.
    Now, i want to remove that new assigned Char. (WWDOC)from the operating concern (OOCC). I did't find any option in the menu also.
    Appreciate your help.....
    T&R
    VVR

    Hi Sasi,
    Iam not able to push back that char. from my operating concern. In help it is given you have to delete the data contents in the table before pushing back. Please let me know if any other option available.
    Thanks for your reply.
    VVR

  • How to clear the power up reset states

    my pci 7344 is  in the power up reset state. How to clear the power up reset state of an 7344 programmatically. Using clear power up reset state in block diagram doesnt seem to work. Give a possible solution

    This is the VI I use to initialize a motion controller. It clears the power up reset if needed and then initialize the controller with the specified configuration (previously created with MAX).
    Sorry for the french comments.
    Attachments:
    Initialiser interface avec gestion power up reset (LV8).vi ‏26 KB

  • How to boldface the header for ONE column

    hi,
    I want to know how to boldface the header for ONE column. The following will boldface the header for all the columns in the table
    table.getTableHeader().setFont(new java.awt.Font("Dialog", 1, 12));
    Thanks.
    Jrabi

    jtable.getColumnModel().getColumn( indexOfBoldColumn ).setHeaderRenderer( TableCellRenderer aRenderer )

  • How to Upload the Materials for one Plant and then copy the same to all oth

    Hi All,
       I am using Material Types NonStock, Service, Spare Parts and Trading.
       How to Upload the Materials for one Plant and then copy the same to all other plants.
    can anybody give response for this requirement.
    Regards...
    <b></b>

    Hi,
    Using MM01 Only we can upload Plant Details.
    If you want to extend to other plant also, Use MM01 and select Plant view and give new plant details.
    If you want to copy from one plant to another plant after selecting Plant view , next screen you can select From Plant and To Plant Details.
    Reward Points If it helps you.
    Regards,
    Murali K

  • How to achieve the project is obligatory entry when creating transport requ

    Hello
    How to achieve the project is obligatory entry when creating transport request

    In T-code SE03, under Administration -> Display/Change Request Attributes
    Select "SAP_CTS_PROJECT" and hit the change button and then change the value of "Default for All Clients" to Mandatory
    Hope this helps.
    Thanks,
    Naveed

  • How to transfer the logins from one instance to another instance in sql2008r2

    how to transfer the logins from one instance to another instance in sql2008r2

    Hi Ganesh,
    According to your description, you want to know how to transfer the logins from one instance to another instance for SQL Server 2008 R2. To do this, besides dave’s post, you could also use
    'Copy Database Wizard' in SQL Server Management Studio, or the component
    'transfer Login task' in SQL Server Integration Services.
    Regards,
    Michelle Li

  • How to mirror the screen from one ipad2 to another ipad2?

    How to mirror the screen from one ipad2 to another ipad2?
    When writing in f.ex. Pages on one iPad i wish to see it in realtime on the other ipad.
    How is that done???

    That functionality is not built into the iPad, so you'd need a third-party app of some sort. I'm not aware of any app that allows mirroring from one iPad to another iPad, but perhaps someone else will know of something I've missed.
    Regards.

  • OpenScript: 1.     How to move the scripts from one location to another location. in OpenScript; Copy, paste or Import, export

    How to move the scripts from one location to another location. Copy, paste or Import, export

    Both way you can do.. Difference is - if you copy paste to another folder script dependencies will not move with the same( ie Assets added), whereas if you export and import the script all dependencies will be correlated automatically

  • How to achieve the best quality when doing a narration?

    Hello,
    I'm trying to figure out how to achieve the best possible narration in a documentary I'm doing using the FCP voice over tool, a USB mic, and Final Cut Studio's audio filters. Am I on the right track? How do I clean up an average voice over narration? Do I need additional equipment? Any advice would be appreciated.
    Thanks,
    Jordan

    The best thing you can do is to record it properly in the first place - if you want it to sound good. The environment you record in is VERY important as is the choice of mic you use ... most of the consumer USB mics aren't all that great in terms of quality.
    Record in an acoustically flat room with good sound dampening. Even a clothes closet will do in a pinch. Record through a mixer so you can monitor the VO artist as they record. I've found it better to record to tape (camera or VTR) with a pro mic than to use FCP's voice over tool.
    -DH

Maybe you are looking for

  • Macbook to Sony Bravia HDMI

    Help. I have a cable and adaptor to connect my macbook to my sony bravia tv. On the TV I get the purpley sunrise picture and if I drag the macbook screen image to the right it appears on the tv (like it is on the next page), but obvioulsly the two ar

  • Dynamics AX 2012 R3: How to populate Payment Reference field automatically?

    Hi guys I am trying to configure AX 2012 (R3) to populate the Payment Reference field automatically when processing payments through a payment journal. I have looked for a number sequence in the AR/AP parameters but so far with no luck. Please advice

  • Call VB Script From ABAP Program

    Hi, I need to call a VBS program from an abap program.  This abap will run on both 4.6 and 4.0. I would be very grateful for any suggestions on how this can be done. Thanks and Kindest Regards Danielle

  • No CF card error - card is fine on PC though

    Hi all, I have a EOS 300D (yes I know it's old, but it's good) Since I last took the card out to transfer everything to my PC, I'm getting "No CF card" error when the card's in. At first I thought it must be the card, but I've since put it on a card

  • Help, unsucessful back up restore of library.

    Got a new iPod 120gb for Christmas. Plugged into computer and found not compatable with 10.3.9. My computer is iMac G4 800mhz and can not handle the new 10.5 so I purchased a 10.4 off of ebay and it was a Server version. I was told that I could not j