Average Sales per month query

Experts,
I worked on this query and was able to get the average Sales for 2009.
SELECT T0.CardCode, T0.CardName, (SUM(T1.Debit) - sum(T1.Credit)) AS '2009', ((SUM(T1.Debit) - sum(T1.Credit))/12)
FROM  OCRD T0
LEFT JOIN JDT1 T1 ON T1.ShortName = T0.CardCode LEFT JOIN JDT1 T2 ON T2.ShortName = T0.CardCode WHERE T0.CardType = 'C' AND Year(T1.Duedate) = 2009 Group By T0.CardCode, T0.CardName
How can I also include the average sales for 2010?
Thanks,
Marli

Hi Marli,
Try this:
SELECT T0.CardCode, T0.CardName, (SUM(T1.Debit) - sum(T1.Credit)) AS '2009',
((SUM(T1.Debit) - sum(T1.Credit))/12) AS '2009 Avg',(SUM(T2.Debit) - sum(T2.Credit)) AS '2010',
((SUM(T2.Debit) - sum(T2.Credit))/Month(GetDate()))
FROM  OCRD T0
LEFT JOIN JDT1 T1 ON T1.ShortName = T0.CardCode AND Year(T1.Duedate) = 2009
LEFT JOIN JDT1 T2 ON T2.ShortName = T0.CardCode AND Year(T2.Duedate) = 2010
WHERE T0.CardType = 'C'
Group By T0.CardCode, T0.CardName
Thanks,
Gordon

Similar Messages

  • Sales Per Month

    Hi..
    How do u find sales per month for a company?
    I have seen FS10N in GL Account display of the sales account but i am not able to comprehend as to what is the exact sales figure?
    Please help?
    Regards,
    Kiran

    Hi Kiran,
    check this may be it can help you.
    Tcode: <b>MCH:</b> - STRPS
    for more info <a href="http://help.sap.com/search/highlightContent.jsp">click here</a>
    Regards,
    Venu.
    Message was edited by:
            Venu Narayana

  • Show sales per month

    Hi,
    Are trying to make a report showing the sales amount planned to be shipped out per month, having the salesprice for each Project in a textfield (text 24) trying to summarize all items that are have finishdate within the current month.
    Is this, or someting similar possible to do in Project? Have spent some hours now unable to find a solution.
    Kind regards //Anders

    Hi Anders,
    May I suggest a different approach to manage the data required for your report?
    I would create a new cost resource with the Accrue At = End
    Then you can build your project plan, assign your resources and finally build a custom report
    When you build the custom report, Time (can be changed to display months) can be use for the Field List (Resources) and, if you need,a filter for a limited number of resources can be applied
    Hope this helps
    Paul

  • Query sales per month per customer

    Hello,
    I have a query for the months january and february working. Now I want to add more months.
    When I do this, the query works, BUT I get very strnage amounts.
    Instead of 20,000 I get an amount of 1.650.000
    Can someone please tel me where I go wrong?
    SELECT T0. [CardCode] ,
    T0. [CardName] ,
    (SUM (T1.Debit) - SUM (T1.Credit ) ) AS ' [November 2013] ' ,
    (SUM (T2.Debit) - SUM (T2.Credit ) ) AS ' [December 2013] ' ,
    (SUM (T3.Debit) - SUM (T3.Credit ) ) AS ' January ' ,
    (SUM (T4.Debit) - SUM (T4.Credit ) ) AS ' February ' ,
    (SUM (T5.Debit) - SUM (T5.Credit ) ) AS ' March ' ,
    (SUM (T6.Debit) - SUM (T6.Credit ) ) AS ' April '
    FROM dbo.OCRD T0
    LEFT JOIN dbo.JDT1 T1 ON T1.ShortName = T0. CardCode AND Month (T1.DueDate ) = 1 AND Year (T1. DueDate ) = Year (GetDate ( ) ) AND T1. TransType in (13, 14)
    LEFT JOIN dbo.JDT1 T2 ON T2.ShortName = T0. CardCode AND Month (T2.DueDate ) = 2 AND Year (T2. DueDate ) = Year (GetDate ( ) ) AND T2. TransType in (13, 14)
    LEFT JOIN dbo.JDT1 T3 ON T3.ShortName = T0. CardCode AND Month (T3.DueDate ) = 3 AND Year (T3. DueDate ) = Year (GetDate ( ) ) AND T3. TransType in (13, 14)
    LEFT JOIN dbo.JDT1 T4 ON T4.ShortName = T0. CardCode AND Month (T4.DueDate ) = 4 AND Year (T4. DueDate ) = Year (GetDate ( ) ) AND T4. TransType in (13, 14)
    LEFT JOIN dbo.JDT1 T5 ON T5.ShortName = T0. CardCode AND Month (T5.DueDate ) = 5 AND Year (T5. DueDate ) = Year (GetDate ( ) ) AND T5. TransType in (13, 14)
    LEFT JOIN dbo.JDT1 T6 ON T6.ShortName = T0. CardCode AND Month (T6.DueDate ) = 6 AND Year (T6. DueDate ) = Year (GetDate ( ) ) AND T6. TransType in (13, 14)
    WHERE T0. CardType = 'C'
    Group By T0. [CardCode] , T0. [CardName]

    Hi,
    Please check any manual journal entry posted for that month.
    Thanks & Regards,
    Nagarajan

  • Sales By Month Query

    Hello -
    Any way to adjust the below query to also include Credit Memo / Returned Items?
    Also, does it include freight amt?
    SELECT T0.State1 AS 'Bill-to State', (SELECT SUM(T1.DocTotal) FROM OINV T1 with (NOLOCK) INNER JOIN OCRD T2 ON T2.CardCode=T1.CardCode
    WHERE MONTH(T1.DOCDATE) = 1 AND T2.State1 = T0.State1
    AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'JAN Amt'
    FROM dbo.OCRD T0 LEFT JOIN dbo.OINV T1 ON T1.CardCode = T0.CardCode
    GROUP BY T0.State1
    ORDER BY T0.State1
    Thanks,
    Mike

    Hi Mike,
    That might be too long for a year.  Try this to see:
    SELECT T0.State1 AS 'Bill-to State', (SELECT SUM(T1.DocTotal) FROM OINV T1 with (NOLOCK) INNER JOIN OCRD T2 ON T2.CardCode=T1.CardCode
    WHERE MONTH(T1.DOCDATE) = 1 AND T2.State1 = T0.State1
    AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) - ISNULL((SELECT SUM(T1.DocTotal) FROM ORIN T1 with (NOLOCK) INNER JOIN OCRD T2 ON T2.CardCode=T1.CardCode
    WHERE MONTH(T1.DOCDATE) = 1 AND T2.State1 = T0.State1
    AND YEAR(T1.DOCDATE) = YEAR(GETDATE())),0) AS 'Jan Amt'
    FROM dbo.OCRD T0 LEFT JOIN dbo.OINV T1 ON T1.CardCode = T0.CardCode
    LEFT JOIN dbo.ORIN T3 ON T3.CardCode = T0.CardCode
    GROUP BY T0.State1
    ORDER BY T0.State1
    Thanks,
    Gordon

  • Sales per Working Days

    I have a requirement to report the average sales per number of working days in the period. I have created a function module that can access the factory calendar and compute the number of working days in a given year/month and have populated a key figure on each record with the number of work days in the period the transaction took place in.
    When I display the number of working days by year/period in a report of course it adds up the days from each transaction and gives false numbers. This seems like it should be a no brainer, but I can't find an easy solution. Can anyone help me with displaying the correct number?
    Thanks in advance.

    Hi
    Try this logic:
    create an avarage Working Days KF1.
    its the working days / Rec Count.
    This KF if you group on CalYearMonth will show the sum
    of the numbers for that motnh.
    then if you want you can take KF1 and create another KF,
    lets say KF2 that is total Sales / KF1.
    I hope it helps.
    Reg's
    Edan

  • Problem with bex query listing sales "this month" and "same month last year

    Hi,
    I've created a query in BW BEx, where I have a mandatory variable for 0calmonth, and I list 0material and sales (in volume, liter). And I have a restricted key figure giving me sales (volume in liter) restricted with 0calmonth = variable - 12, to give me the sale for the same month the user select, previous year.
    This seems to be working, the sum is correct, but when adding up the number for the sales in the month previous year, the numbers does not fit the sum in the end.
    I think the report only lists materials with sales the month selected in the variable, if a material has not been sold that month, but in the same month last year, it's not listed in the reports, but it's added in the sum in the end.
    Example.
    We have three records like this:
    material - calmonth - volume
    101 - 01.2010 - 5
    101 - 01.2011 - 8
    201 - 01.2010 - 7
    The report will give the following (calmonth variable = 01.2011)
    Material - volume this month - volume same month last year
    101 - 8 - 5
    Sum 8 - 12
    Any way to solve this issue? We noticed because we run BO - Webi on top of the BEx query, and BO sum's the values per material, and in webi the report would give us the sum 8 and 5.
    Any input is appreciated.
    Regards,
    Øystein

    Hi,
    thanks for your reply.
    The error is that the report only seems to list materials that has been sold "this month", and if the same material was sold the same month last year, it will also list the volume for this.
    But if the material is only sold in the same month last year, it's not listed in the report, but it's calculated into the sum at the end.
    The report is listing material, which is why the error presents itself, as you said
    Getting 8 minus 12 is correct unless you drill down by material. In that case, it should be 8 minus 5 and 0 minus 7.
    The row with 0 - 7 is not shown, and my guess is that the report will only list materials that has sales this month (which has been selected in the variable)
    Regards,
    Øystein
    Edited by: Oystein Gundersen on Mar 21, 2011 4:36 PM

  • Dramatic Drop in Books Sales from Over 270 per month to less than 70. Any answers as to why? Has this happened to others?

    Sales of my books averaged over 270 per month for almost all of 2011 and 2012 and for January of 2013--then in February of 2013 and continuing to the present, sales dropped to less than 70 per month.
    The sudden drop from over 270 per month to less than 70 per month with sales suddenly falling off the fiscal cliff in Februrary of 2013 is inexplicable.  I can find no reason for it. 
    Therefore, I am asking other authors: Has this happened to you? Any idea of what changed? I presume something must have changed within the itunes bookstore, or there was a change in the listing of my books.

    In additon to this forum, we contacted Apple Ibookstore support and this afternoon they may have provided the explantion:
    According to Apple:
    "iBookstore that change frequently including top charts and any featured placement sections (IE: New and Noteworthy sand other special or seasonal sections). All featured placement is solely at the discretion of Apple and isn't guaranteed. If your book was in one of these prominent sections or top charts before and is no longer there, this might be what you are noticing in your numbers."
    Fortunately for us, our authors probably got us featured placement for 2 years. Unfortunately for us, after 2 years it appears we were shoved aside for another pretty face. Thus, book sales imploded.
    We thank Apple for answering our inquiries and providing us with useful information as to how to (hopefully) drive sales back up.

  • A query with workingdays per month per persons per period

    Can anyone help me on the way in building a difficult SQL query?
    I work with Oracle SQL. It is intended to calculate over a certain period, to find the working days for each month for each person.
    I have a working query for calculate the number of days for 1 months minus holidays
    Select count (*) NUM_WORK_DAYS
    From (
    Select to_date ('01-01-2010 ',' dd-mm-yyyy ') + ROWNUM-1 as day
    From all_objects
    Where ROWNUM <to_number (to_char (last_day ('01-01-2010 '), DD')) + 1)
    Where to_number (to_char (day, 'd')) between 1 and 5
    And not exists (select NULL
    From HOLIDAY
    Where Holiday.hol=day)
    There is a datetable with the following structure where I can get the periods:
    DATES
    YEAR | MONTH | WEEK | SD
    2010 | 201002 | 201006 | 09/02/2010
    All required months are present
    It is intended that the user give a beginning and a end time specify.
    I have a table of workingdays per person named
    CALENDAR
    CAL | MON | TUE | WED | THU | FRI | SAT | SUN
    Person | Y | Y | N | Y | Y | N | N
    And a table of holidays
    HOLIDAY
    CAL | HOL
    Person | 01/01/2010
    How can I combine the query for working days and build a query that returns for multiple people over multiple months the number of workingdays per month? I will ask the user to give a beginning period and a end period
    I am aware that I ask a lot of your time, but I can not imagine the solution myself. Many thanks in advance
    Gr,
    Els

    You can do something like this:
    SQL> select * from calendar;
        PERSON M T W T F S S
             1 Y Y N Y Y N N
             2 Y Y Y Y Y N N
    SQL> select * from holiday;
        PERSON HOL
             1 12-FEB-10
             2 09-FEB-10
    SQL> define start_day=2010-02-01
    SQL> define end_day=2010-02-20
    SQL> with period as (
      2  select DATE '&start_day' start_date, DATE '&end_day' end_date
      3    from dual),
      4  days as (
      5  select start_date+level-1 day
      6    from dual,period
      7  connect by level <= end_date-start_date+1),
      8  mycal as (
      9  select person, 'monday' day, mon works from calendar union all
    10  select person, 'tuesday' day, tue from calendar union all
    11  select person, 'wednesday' day, wed from calendar union all
    12  select person, 'thursday' day, thu from calendar union all
    13  select person, 'friday' day, fri from calendar union all
    14  select person, 'saturday' day, sat from calendar union all
    15  select person, 'sunday' day, sun from calendar
    16  )
    17  select person, count(0)
    18    from mycal c, days d
    19   where c.day = trim(to_char(d.day,'day'))
    20     and c.works='Y'
    21     and not exists (select 1 from holiday h where h.person=c.person and h.hol=d.day)
    22  group by person;
    old   2: select DATE '&start_day' start_date, DATE '&end_day' end_date
    new   2: select DATE '2010-02-01' start_date, DATE '2010-02-20' end_date
        PERSON   COUNT(0)
             1         11
             2         14The PERIOD view is there only to accept start and end date.
    The DAYS view contains all the days of the period
    The MYCAL view unpivotes the calendar days returning 7 rows for each person, a row per weekday
    Max
    http://oracleitalia.wordpress.com

  • Number of open sales notes/contracts per month

    Kindly inform are there any stanadard reports in SD for following:
    1. Number of open sales notes/contracts per month
    2. Discounts & Credit notes as % of sales
    3. Days sales outstanding report
    4. Number of bounced cheques trends and % of sales
    5. Customer information report
    6. customers segmatation categories report
    will be very thankful to you all.
    thanks
    anya

    for 1& 3 VA05 and XD03--->Sales Summary of Customer
    Regards
    Prabhu

  • Create sales order in ref to quantity contract automatically once per month

    Hi there.
    Is it possible to create a sales order (ZOR) automatically, for example, once per month, in reference to a quantity contract (CQ) for as long as the contract is valid ?
    So, instead of create manually a subsequent order on the contract let it be done automatically. Once per month or once per week or once per .......
    Each contract needs to create it is own sales order. There are approx. 50contracts.
    Would appreciate your help on this.
    cheers !
    Ed

    We can write a BDC and schedule the program every month in the back ground.
    It needs ABAP and Basis help.
    Reward points
    Regards,
    Anbu

  • Averaging Columns (by months of the year)

    Running Oracle 9i
    I have this query which takes fields: ID, Date, and Data and performs a crosstab (matrix) query which has the day column, the 12 months, and the total for each day.
    I have been trying to add averaging for each month at the bottom of the result and total after that so that the result looks like:
    Day Jan Feb Mar ... Oct Nov Dec Total
    1 1.1 2.2 3.3 4.4 5.5 6.6 999.99
    2
    30
    31 3.3 6.6
    (currently looks like the above.. Need to change query so that the next two lines are displayed)
    Average 2.2 4.4 ....... etc.. 5.5 (blank)
    Total 4.4 8.8........ etc... 11.0 999.99
    I tried to use an example of the ROLLUP and just got different errors..
    Here is the current query:
    select to_char(piDate,'dd') as day
    ,sum(decode(to_char(piDate,'mm'),'01',piValue)) as Jan
    ,sum(decode(to_char(piDate,'mm'),'02',piValue)) as Feb
    ,sum(decode(to_char(piDate,'mm'),'03',piValue)) as Mar
    ,sum(decode(to_char(piDate,'mm'),'04',piValue)) as Apr
    ,sum(decode(to_char(piDate,'mm'),'05',piValue)) as May
    ,sum(decode(to_char(piDate,'mm'),'06',piValue)) as Jun
    ,sum(decode(to_char(piDate,'mm'),'07',piValue)) as Jul
    ,sum(decode(to_char(piDate,'mm'),'08',piValue)) as Aug
    ,sum(decode(to_char(piDate,'mm'),'09',piValue)) as Sep
    ,sum(decode(to_char(piDate,'mm'),'10',piValue)) as Oct
    ,sum(decode(to_char(piDate,'mm'),'11',piValue)) as Nov
    ,sum(decode(to_char(pidate,'mm'),'12',piValue)) as Dec
    ,sum(piValue) as Total
    ,max(reportid) as ReportID
    ,max(waterdatatypeid) as WaterDataTypeID
    from LPInflow
    where reportid=14 and pidate >=to_date('2006/01/01','yyyy/mm/dd') and
    pidate <= to_date('2006/12/31','yyyy/mm/dd')
    group by to_char(piDate,'dd'),to_char(piDate,'yyyy');
    Also, the reportid is the same for all, but just using reportid instead of min/max reportid causes the query to fail..
    If I could get the correct query systax it would be great..
    Thanks .Very Much appreciated..

    Hi Swaroop,
                        I have a issue with allocation logic i.e is my scenario require allocation logic or i can write general logic,if yes,can you give a suggestion how to write..
    Scenario is..in my plan..
    I prepared a schedule for SALES planing...for which i have prepared a input scedule..
    My input schedule works like..COLs-SalesAccountits memberset isfiltered using propety i.e test3="C"
                                                     ROWs-ENTITY--its memberset is  filtered using propety i.e Plants="A"
                                                     Time--Taking from CV.
    When i take time 2009.INPUT from CV and enter the data for entity for respect salesaccounts and send the data.NEXT,
    I want to copy the same data to all the months of 2009...for that iam using allocation like
    *RUNALLOCATION
    *FACTOR
    //*USING
    *DIM ENTITY WHAT=Entity;                    WHERE=<<<:              USING=Entity.PLANTS
    *DIM SALESAccount WHAT=SALESACCOUNT;  WHERE=<<<:  USING<>SALESACCOUNT.TEST3
    *DIM TIME WHAT=BAS(%YEAR%.TOTAL); WHERE=<<<;          USING=%TIME_SET%;
    *ENDALLOCATION
    will it work my scenario does i need to add any other logic ...
    Suggest me sol..
    regards,
    Naresh.

  • BEx calculation for 'average sales order value'

    Hi all,
    Can someone tell me how to use BEx query function to compute the <b>'average sales order values' by month</b>? Thank you.
    J.

    Hi John,
         You've two characteristics in the rows, right? Calendar Month and Order Type.
    Try the option Calculate Result as Average of All Values and
    Calculate Single Value as Nothing Defined? See if this works.
    Or else in Modelling,
    In the Info Object Create/Change screen, you can specify an Exception Aggregation based on
    <b>Aggregate Reference Characteristic</b> Calendar Month.
    I think there's an option for Average Values in the <b>Exception Aggregation</b> tab.
    For more Information,
    http://help.sap.com/saphelp_nw04/helpdata/en/75/21054da1392649948e5b94e4fc4bce/content.htm
    Hope this helps.
    Regards
    Hari
    Message was edited by: Hari Krishnan K

  • Report Sales Per Customer

    Hello to all!
    i have a requirement to make a query that will bring me report for Sales Per Customer
    the desired fields are the following
    CardCode
    CardName
    --, (Select sum(T6.LineTotal) from inv1 t6  where t6.docentry=t0.docentry) 'Price Bef. Disc.'
    , (Select t5.linetotal from inv3 t5 where t5.docentry=t0.docentry and t5.expnscode in ('6','7')) as 'Freight'
    --, (Select t5.linetotal from inv3 t5 where t5.docentry=t0.docentry and t5.expnscode='11') as 'W/TAX'
    VatSum
    .DocTotal
    SlpName
    till now i have written the following code
    SELECT t0.docdate as 'Doc. Date', t0.docnum as 'Doc No.', T0.CardCode AS 'Customer Code', T0.CardName as 'Customer Name', (Select sum(T6.LineTotal) from inv1 t6 where t6.docentry=t0.docentry) 'Price Bef. Disc.', (Select t5.linetotal from inv3 t5 where t5.docentry=t0.docentry and t5.expnscode in ('6','7')) as 'Freight', (Select t5.linetotal from inv3 t5 where t5.docentry=t0.docentry and t5.expnscode='11') as 'W/TAX',T0.VatSum,  sum(T0.DocTotal) 'Doc. Total', T1.SlpName as 'Account Manager' FROM OINV T0 INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode inner join ocrd t2 on t0.cardcode=t2.cardcode inner join ocrg t3 on t2.groupcode=t3.groupcode WHERE (T0.DocDate between '[%0]' and '[%1]')
    group by T0.CardCode, T0.CardName, T1.SlpName, t0.docnum, t0.totalexpns, t0.docentry, t0.docdate,T0.VatSum
    union
    SELECT t0.docdate as 'Doc. Date', t0.docnum as 'Doc No.', T0.CardCode AS 'Customer Code', T0.CardName as 'Customer Name',(Select (-1)*sum(T6.LineTotal) from rin1 t6 where t6.docentry=t0.docentry) 'Price Bef. Disc.', (Select (-1)*(t5.linetotal) from rin3 t5 where t5.docentry=t0.docentry and t5.expnscode in ('6','7')) as 'Freight', (Select (-1)*(t5.linetotal) from rin3 t5 where t5.docentry=t0.docentry and t5.expnscode='11') as 'W/TAX', (-1)*T0.VatSum, (-1)*sum(T0.DocTotal) 'Doc. Total',T1.SlpName as 'Account Manager' FROM ORIN T0 INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode inner join ocrd t2 on t0.cardcode=t2.cardcode inner join ocrg t3 on t2.groupcode=t3.groupcode WHERE (T0.DocDate between '[%0]' and '[%1]')
    group by T0.CardCode, T0.CardName, T1.SlpName, t0.docnum, t0.totalexpns, t0.docentry, t0.docdate,T0.VatSum
    but i would like only once to be displayed each customer
    do you have any idea?

    issue resolved
    SELECT
    T0.CardCode AS 'Customer Code'
    , T0.CardName as 'Customer Name'
    ,(select sum(t5.linetotal) from inv1 t5 INNER JOIN oinv T6 ON T6.DOCENTRY=T5.DOCENTRY where t6.cardcode=t0.cardcode and t5.docdate between '[%0]' and '[%1]') 'Price Bef. Disc.'
    ,(Select sum(t7.linetotal) from inv3 t7 inner join oinv t6 on t6.docentry=t7.docentry where t6.cardcode=t0.cardcode and t7.expnscode in ('6','7') and t6.docdate between '[%0]' and '[%1]') as 'Freight'
    ,(Select sum(t7.linetotal) from inv3 t7 inner join oinv t6 on t6.docentry=t7.docentry where t6.cardcode=t0.cardcode and t7.expnscode ='11' and t6.docdate between '[%0]' and '[%1]') as 'W/TAX'
    ,(select sum(t8.vatsum) from oinv t8 where t8.cardcode=t0.cardcode and t8.docdate between '[%0]' and '[%1]') as 'VatSum'
    ,sum(T0.DocTotal) 'Doc. Total'
    , T1.SlpName as 'Account Manager'
    FROM OINV T0
    INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode
    WHERE (T0.DocDate between '[%0]' and '[%1]')
    group by T0.CardName, T1.SlpName,T0.CardCode
    union
    SELECT
    T0.CardCode AS 'Customer Code'
    , T0.CardName as 'Customer Name'
    ,(select sum(t5.linetotal) from rin1 t5 INNER JOIN orin T6 ON T6.DOCENTRY=T5.DOCENTRY where t6.cardcode=t0.cardcode and t5.docdate between '[%0]' and '[%1]') 'Price Bef. Disc.'
    ,(Select sum(t7.linetotal) from rin3 t7 inner join orin t6 on t6.docentry=t7.docentry where t6.cardcode=t0.cardcode and t7.expnscode in ('6','7') and t6.docdate between '[%0]' and '[%1]') as 'Freight'
    ,(Select sum(t7.linetotal) from rin3 t7 inner join orin t6 on t6.docentry=t7.docentry where t6.cardcode=t0.cardcode and t7.expnscode ='11' and t6.docdate between '[%0]' and '[%1]') as 'W/TAX'
    ,(select sum(t8.vatsum) from oinv t8 where t8.cardcode=t0.cardcode and t8.docdate between '[%0]' and '[%1]') as 'VatSum'
    ,sum(T0.DocTotal) 'Doc. Total'
    , T1.SlpName as 'Account Manager'
    FROM orin T0
    INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode
    WHERE (T0.DocDate between '[%0]' and '[%1]')
    group by T0.CardName, T1.SlpName,T0.CardCode

  • Storing and calculating sales per item

    The case: We have a item, on that item we have a fee. If the item has sold more than 1000 copies, the fee will drop. Therefor i need to have a place that calculates/stores total sales per item. This can then be used to set the fee when i run my stored procedure
    for sales etc. 
    Database explained shortly: 
    The sales database looks like this: 
    ItemID, SalesDate, Quantity, Name.
    Example: 
    1399, 2014-01-01, 2, Fompa.
    1081, 2014-01-01, 13, Asddd. 
    1399, 2014-01-03, 1, Fompa. 
    Etc. 
    The item database looks like this: 
    ItemID, Name, Author, etc
    Now my boss asked me if i maybe should add total sales to the item database, but how is that possible? 
    I have also tried to gather all items and show the total sales, but something goes wrong, the itemID are not grouping together..
    here is the query: select ItemID, QUANTITY from BOOK_SALES group by ItemID, QUANTITY order by MAX(quantity) DESC
    If i get this query right, is it possible to store the query within a database table? 

    Hey, thanks for a fast answer. 
    I modified your query a little, 
    select
    itemid, sum(quantity) from book_sales group by
    itemid order by MAX(quantity) DESC
    but still, all of the itemIDs are not being grouped together. 
    Results show something like this: 
    1399, 981
    1081, 344
    1399, 199
    etc..

Maybe you are looking for