SQL- Getting Subtotal From a Query

Hi,
I need to run a query where I can get a subtotal for each items in a table.  The query should produce something like:
3 apple
4 grape
1 orange
I did a SUM and COUNT function but, I get the total records (8) in the table instead of the subtotals.
SELECT      id, SUM(fruit) AS Total
FROM         table
WHERE     ORDER BY fruit
Any suggestions would be great.
Thanks,
Jenn

try this
SELECT     fruit,count(*) as fruit_count, SUM(fruit) AS Total
FROM         table
WHERE     group BY fruit

Similar Messages

  • How to get key from MDX Query

    Hi All,
    how to get key from mdx query ?
    example :
    SELECT [Measures].[67822GFASOU7KUT6FKHSQ34FV] ON COLUMNS NON EMPTY CROSSJOIN([ZCOMPANY].MEMBERS, [ZMILL].MEMBERS) ON ROWS FROM ZODS_GL/ZODS_GL_001
    the result from this mdx query are zcompany text and zmill text, how to get company key and mill key ?
    Regards
    JeiMing

    hi Jeiming,
    to get key in mdx, you can try something like
    [ZCOMPANY].[LEVEL01].MEMBERS
    properties [ZCOMPANY].[2ZCOMPANY]
    following threads may useful
    Extracting texts with MDX
    MDX Statement - display only keys for characterstics and their dis. attrib.
    hope this helps.

  • Bapi to get data from BW query

    Hi,
    Does anyone familiar with bapi function to get data from BW query .???
    I'm trying to use  RS_VC_GET_QUERY_VIEW_DATA_FLAT  but i get only the SUM rows of the query
    and not the details rows (drill down).
    i want to export the data of BW query to table and i need all the query data.
    if someone have an example or documention its will be great.
    Thanks.

    Hi,
    Does anyone familiar with bapi function to get data from BW query .???
    I'm trying to use  RS_VC_GET_QUERY_VIEW_DATA_FLAT  but i get only the SUM rows of the query
    and not the details rows (drill down).
    i want to export the data of BW query to table and i need all the query data.
    if someone have an example or documention its will be great.
    Thanks.

  • Running a SQL Stored Procedure from Power Query with Dynamic Parameters

    Hi,
    I want to execute a stored procedure from Power Query with dynamic parameters.
    In normal process, query will look like below in Power Query. Here the value 'Dileep' is passed as a parameter value to SP.
        Source = Sql.Database("ABC-PC", "SAMPLEDB", [Query="EXEC DBO.spGetData 'Dileep'"]
    Now I want to pass the value dynamically taking from excel sheet. I can get the required excel cell value in a variable but unable to pass it to query.
        Name_Parameter = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
        Name_Value = Name_Parameter{0}[Value],
    I have tried like below but it is not working.
    Source = Sql.Database("ABC-PC", "SAMPLEDB", [Query="EXEC DBO.spGetData Name_Value"]
    Can anyone please help me with this issue.
    Thanks
    Dileep

    Hi,
    I got it. Below is the correct syntax.
    Source = Sql.Database("ABC-PC", "SAMPLEDB", [Query="EXEC DBO.spGetData '" & Name_Value & "'"]
    Thanks
    Dileep

  • Get age from DOB query problem

    Hi I'm a bit of a noob. I've found this query and got it to work but I want to find all the people over the age of 30. How do I go about doing this?
    SELECT FLOOR( MONTHS_BETWEEN( CURRENT_DATE, DOB ) / 12 ) AS person_age FROM Customer
    This shows everyones age.
    Many thanks

    It's working fine
    This is example to illustrate find age which are greater than 25.
    SQL> select *
    2 from (
    3 SELECT FLOOR( MONTHS_BETWEEN( CURRENT_DATE, hiredate ) / 12 ) AS person_age
    4 FROM emp
    5 )
    6 where person_age > 25
    7 /
    PERSON_AGE
    27
    27
    27
    27
    27
    27
    27
    27
    27
    27
    27
    PERSON_AGE
    26
    12 rows selected.
    Actual requirement is as follows:
    SQL> select *
    2 from (
    3 SELECT FLOOR( MONTHS_BETWEEN( CURRENT_DATE, hiredate ) / 12 ) AS person_age
    4 FROM emp
    5 )
    6 where person_age > 30
    7 /
    Edited by: venkata on Dec 15, 2008 11:02 AM

  • Get data from bw query to r/3

    Hi,
    There is a query defined in BW with some variables. The current process is user is executing the query with necessary variables and the query result output is saving as csv file and this file is used in r3 to update the data in r3.
    Now we have to make this process automate. We have to get the query result data from BW to R3.
    We have a constraint of not using the Open hub method in BW.
    Is there any function module or any standard program to get the query result data from BW to r3.
    Any help is highly appreicated.

    able to resolve the issue..
    creating trusting RFC connection solved the problem

  • How to get values from a query string in URL in a jsf page?

    if i have a url, http://my.com/?name=john+smith, how do i get the values from that url in a jsf page and then pass those values to a servlet?
    i know how to do that in jsp using "request.getParamter("name")" and save it in a bean and then forward to a servlet. But what about in jsf?

    Hello,
    Try this:
    Map requestMap = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
    String name = (String) requestMap.get("name");If isn't worked one of these methods probably will solve your problem.
    FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
    FacesContext.getCurrentInstance().getExternalContext().getRequestHeaderMap();hth.

  • Use APD to get Rank from TopN query result to target for Universe

    Hello,
    I am trying to take a query result set where I am calculating a key figure as Rank and run it through an APD to write to a DSO.
    This is a top 5 query for a dashboard.  I keep getting an MDX failure on the query.
    Any ideas? 
    My ultimate goal is to set up a process to take TopN query results and get them into a target that can be used in a Universe.
    Thanks,
    Chris

    Hello Chris,
    I recommend to post this query to the [Universe Designer and Business Views Designer|Semantic Layer; forum.
    This forum is dedicated to topics related to the universes and business views.
    It is monitored by qualified technicians and you will get a faster response there.
    Also, all Enterprise Information Management queries remain in one place and thus can be easily searched in one place.
    Thanks a lot,
    Falk

  • How to get fieldnames from Select * query ?

    How can I get the fieldnames returned with a SELECT * query ?
    When I use GetFieldName or GetFieldOriginalName I only get fieldnames of "*".

    You should use the fields collection, in the OraDynaset object.
    All you need to do is :
    for i = 0 to Recordset.Fields.Count -1
    debug.print Recordset.Fields(i).name
    debug.print Recordset.Fields(i).OriginalName 'this will print the field's name before an alias
    next i

  • Get XSD from Report Query

    APEX 4.0.2
    Oracle 11.2.0.1.0
    Hello,
    We are trying to retrieve the XML Schema for a Report Query.
    The following code example is working, but the 'xsd' parameter for p_document_format is not documented.
    Is 'xsd' a supported parameter value for APEX_UTIL.GET_PRINT_DOCUMENT?
    v_blob := APEX_UTIL.GET_PRINT_DOCUMENT (
        p_application_id      => NV('APP_ID'),
        p_report_query_name   => 'test',
        p_report_layout_name => null,
        p_report_layout_type => null, 
        p_document_format     => 'xsd',
        p_print_server => null);Thank you in advance!

    Hi Eric,
    We have four different versions of apex_util.get_print_document, so depending on what you want to do, you can create PDFs and other document types based on your own XML data, your own style-sheets, or referencing pre-defined report-queries, with pre-defined layouts, or custom layouts. We support the output formats I've previously listed for all four versions. However the internal implementation of those APIs is different for the APIs that reference report queries and those that reference custom XML data. When referencing report queries, APEX first loads and executes those queries and generates the XML data, and then passes the XML on the the print rendering engine. The parsing and execution of those queries happens to use the same internal functions that are also used on the report query edit page, where you have buttons that allow for downloading XML and XML Schema representations of your report query. Those XML and XSD documents are intended to be used with the BI Publisher Word Plug-In or third-party XSL design tools to design report layouts. Now given that the same internal functions are used, you can actually generate XML Schema (XSD) documents using the apex_util.get_print_document API, but only with those versions that let you reference a pre-defined report query. This isn't officially supported, so I can guarantee that this behavior won't change in the future, though I don't see why we would change that. The main reason for supporting XML in those APIs is really to test the print functionality without requiring a print rendering engine. But looks like there are some other use cases for those output formats as well.
    Hope the helps,
    Regards,
    Marc

  • After running Export from Access query the query empties itself

    Hello,
    I'm facing a weird problem in Access 2010. I have several queries that I sometimes export to both Excel and HTML formats, sometimes when I export, the query empties itself. Meaning, the SQL code disappears from the query and I have to rebuild it before I
    can use it again.
    Does anyone understand how this can happen?
    Kind regards,
    Rob Demandt

    Dear Kev,
    Sure, the queries are relatively simple, an example:
    "SELECT AC_DEV_01_AUTOPO_NOSOURCE_US50.F1 AS Material, AC_DEV_01_AUTOPO_NOSOURCE_US50.EersteVanF2 AS [Material Description], AC_DEV_01_AUTOPO_NOSOURCE_US50.EersteVanF6 AS Vendor
    FROM AC_DEV_01_AUTOPO_NOSOURCE_US50
    WHERE (((AC_DEV_01_AUTOPO_NOSOURCE_US50.EersteVanOpProc)="PJ"));"
    The export is indeed invoked using a MACRO that uses the ExportWithFormatting syntax to export a few queries in a row to XLSX and HTML.
    Kind regards,
    Rob Demandt

  • Sql query to get numbers from 0 to 99

    How can we write an sql query to get values from 0 to 99 ... this shouldn't be coming from any table

    Bawer wrote:
    Result: (quickly replied by oracle)
    SQL-Error: ORA-30009 (Not enough memory for connect by - 1GB reserved for oracle on VirtualBox)Oracle version? Takes about 8 seconds on my:
    SQL> select * from v$version
      2  /
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
    PL/SQL Release 10.2.0.4.0 - Production
    CORE    10.2.0.4.0      Production
    TNS for 32-bit Windows: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    Elapsed: 00:00:00.14
    SQL> select count(*) from (
      2  SELECT LEVEL - 1
      3  FROM DUAL
      4  CONNECT BY LEVEL <= 10000000
      5  )
      6  /
      COUNT(*)
      10000000
    Elapsed: 00:00:07.76
    SQL> SY.

  • How to get sql server performance counters using query?

    Hai i want to see my sql server performance counters like, Full Scans/sec,  Buffer
    Cache Hit Ratio,  Database Transactions/sec, User
    Connections, Average Latch Wait Time (ms), Lock
    Waits/sec, Lock Timeouts/sec, Number
    of Deadlocks/sec, Total Server Memory, SQL
    Re-Compilations/sec, User Settable Query. If any one know how to get it by using query means, please help me.
    Thanks in advance

    Hello,
    Below is query created by Jonathan Kehayias for measuring Perfom counters using DMV sys.dm_os_performance_counter.
    You can download book from below link
    https://www.simple-talk.com/books/sql-books/troubleshooting-sql-server-a-guide-for-the-accidental-dba/
    DECLARE @CounterPrefix NVARCHAR(30)
    SET @CounterPrefix = CASE WHEN @@SERVICENAME = 'MSSQLSERVER'
    THEN 'SQLServer:'
    ELSE 'MSSQL$' + @@SERVICENAME + ':'
    END ;
    -- Capture the first counter set
    SELECT CAST(1 AS INT) AS collection_instance ,
    [OBJECT_NAME] ,
    counter_name ,
    instance_name ,
    cntr_value ,
    cntr_type ,
    CURRENT_TIMESTAMP AS collection_time
    INTO #perf_counters_init
    FROM sys.dm_os_performance_counters
    WHERE ( OBJECT_NAME = @CounterPrefix + 'Access Methods'
    AND counter_name = 'Full Scans/sec'
    OR ( OBJECT_NAME = @CounterPrefix + 'Access Methods'
    AND counter_name = 'Index Searches/sec'
    OR ( OBJECT_NAME = @CounterPrefix + 'Buffer Manager'
    AND counter_name = 'Lazy Writes/sec'
    OR ( OBJECT_NAME = @CounterPrefix + 'Buffer Manager'
    AND counter_name = 'Page life expectancy'
    OR ( OBJECT_NAME = @CounterPrefix + 'General Statistics'
    AND counter_name = 'Processes Blocked'
    OR ( OBJECT_NAME = @CounterPrefix + 'General Statistics'
    AND counter_name = 'User Connections'
    OR ( OBJECT_NAME = @CounterPrefix + 'Locks'
    AND counter_name = 'Lock Waits/sec'
    OR ( OBJECT_NAME = @CounterPrefix + 'Locks'
    AND counter_name = 'Lock Wait Time (ms)'
    OR ( OBJECT_NAME = @CounterPrefix + 'SQL Statistics'
    AND counter_name = 'SQL Re-Compilations/sec'
    OR ( OBJECT_NAME = @CounterPrefix + 'Memory Manager'
    AND counter_name = 'Memory Grants Pending'
    OR ( OBJECT_NAME = @CounterPrefix + 'SQL Statistics'
    AND counter_name = 'Batch Requests/sec'
    OR ( OBJECT_NAME = @CounterPrefix + 'SQL Statistics'
    AND counter_name = 'SQL Compilations/sec'
    -- Wait on Second between data collection
    WAITFOR DELAY '00:00:01'
    -- Capture the second counter set
    SELECT CAST(2 AS INT) AS collection_instance ,
    OBJECT_NAME ,
    counter_name ,
    instance_name ,
    cntr_value ,
    cntr_type ,
    CURRENT_TIMESTAMP AS collection_time
    INTO #perf_counters_second
    FROM sys.dm_os_performance_counters
    WHERE ( OBJECT_NAME = @CounterPrefix + 'Access Methods'
    AND counter_name = 'Full Scans/sec'
    OR ( OBJECT_NAME = @CounterPrefix + 'Access Methods'
    AND counter_name = 'Index Searches/sec'
    OR ( OBJECT_NAME = @CounterPrefix + 'Buffer Manager'
    AND counter_name = 'Lazy Writes/sec'
    OR ( OBJECT_NAME = @CounterPrefix + 'Buffer Manager'
    AND counter_name = 'Page life expectancy'
    OR ( OBJECT_NAME = @CounterPrefix + 'General Statistics'
    AND counter_name = 'Processes Blocked'
    OR ( OBJECT_NAME = @CounterPrefix + 'General Statistics'
    AND counter_name = 'User Connections'
    OR ( OBJECT_NAME = @CounterPrefix + 'Locks'
    AND counter_name = 'Lock Waits/sec'
    OR ( OBJECT_NAME = @CounterPrefix + 'Locks'
    AND counter_name = 'Lock Wait Time (ms)'
    OR ( OBJECT_NAME = @CounterPrefix + 'SQL Statistics'
    AND counter_name = 'SQL Re-Compilations/sec'
    OR ( OBJECT_NAME = @CounterPrefix + 'Memory Manager'
    AND counter_name = 'Memory Grants Pending'
    OR ( OBJECT_NAME = @CounterPrefix + 'SQL Statistics'
    AND counter_name = 'Batch Requests/sec'
    OR ( OBJECT_NAME = @CounterPrefix + 'SQL Statistics'
    AND counter_name = 'SQL Compilations/sec'
    -- Calculate the cumulative counter values
    SELECT i.OBJECT_NAME ,
    i.counter_name ,
    i.instance_name ,
    CASE WHEN i.cntr_type = 272696576
    THEN s.cntr_value - i.cntr_value
    WHEN i.cntr_type = 65792 THEN s.cntr_value
    END AS cntr_value
    FROM #perf_counters_init AS i
    JOIN #perf_counters_second AS s
    ON i.collection_instance + 1 = s.collection_instance
    AND i.OBJECT_NAME = s.OBJECT_NAME
    AND i.counter_name = s.counter_name
    AND i.instance_name = s.instance_name
    ORDER BY OBJECT_NAME
    -- Cleanup tables
    DROP TABLE #perf_counters_init
    DROP TABLE #perf_counters_second
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers

  • Using Get Data From Aggregation event class in SQL Profiler - SSAS 2012

    Hi,
    I'd like to understand better the use of the Get data from aggregation event class in SQL Profiler to monitor a MDX query and which info provide. Fe, does it return the MDX query? Is it possible to use this event class in order to monitor MDX query vs a
    Tabular model?
    In the TechNet documentation, this event class is handled briefly.
    Thanks

    Hi pscorca,
    This event is raised when the storage engine reads data from an aggregation, it may have a negative impact on performance when turned on. If you need to monitor SSAS instance status, we can also use dynamic management view:
    Use Dynamic Management Views (DMVs) to Monitor Analysis Services:
    http://msdn.microsoft.com/en-us/library/hh230820.aspx
    Regards,
    Elvis Long
    TechNet Community Support

  • How to export result set from mysql query browser to .sql in oracle

    Hi folks:
    I was trying to export result set from MySql query browser to Oracle. I could able to do
    File->Export Result Set-> Excel format...
    What I am trying to get is .sql file so that I can run it as a script in my oracle db. Is there any way we can get .sql file with inserts and delimeters ....?
    Did you guys get my question.?
    Please throw some light on this....
    Could be very appreciable ....
    Thanks
    Sudhir Naidu

    Hi
    Create a sql statement which generates the insert statements.
    Something like this:
    select 'insert into table1 (column1, column2, column3) values (' ||
    column1 || ', ' || column2 || ', ' || column3 || ');' from table 1;
    The || sign is the string concatenation sign in Oracle, replace it the appropriate sign in MySql. Export the result set of this query into a file, and you can run it in a SqlPlus.
    Ott Karesz
    http://www.trendo-kft.hu

Maybe you are looking for

  • SEM CPM - Management Cockpit

    Hi Guys, Currently we are working on creating SEM CPM management cockpit and the requirement is as follows, 1.we need to diplay one of the query result directly in the dashboard.(without any graph) 2.We need to create a table display with 3/4 KPI's w

  • Illustrator CS6 Crashes after it opens and click on anything!!!

    Every time I open illustrator and click on the pen icon, open a document, etc etc it crashes. I am using a Mac computer OS X version 10.9. I only have downloaded fonts from dafont.com on this computer. Nothing else has been installed or downloaded. 

  • CUF display or input

    Hi, In BBP_CUF_BADI_2, how to code that a CUF field is to be displayed or hidden ? We try wa_fields-xdisplay = 'X'. or wa_fields-xinput = 'X'. without any success ? Did anybody already succeed in doing this ? Kind regards, Yann

  • How can i digital sign a file using JAVA?

    and how can i verify the digitially signed file was not altered by anyone using JAVA? please provide me with the simpliest way to do this. thanks a lot.

  • X-fi & EAX in tombraider Anivers

    Has anyone found a way to enable EAX in the new game TRA using an X-fi? I mean in an?XPSP2, since MS killed EAX in Vista as I understand it and you need to use the OpenAL file for vistaThx in advance