When count sum ID number total < 300

Afternoon Folks,

I was wondering if someone could help me with a query of code?

I'm counting the number of Packs of Service where the total payment of the amount for each separate sp_id is less than 300 pounds and also more than 300 pounds.

This is the code I have so far:

Select the specialty
count (distinct sp_id) "Service Packs",
Sum (payment_total) "Total paid £»,
round (sum (payment_total) / count (distinct sp_id), 0) 'average spend by MS.
of a3_fact_sms_service_inv
where specialized ("podiatry", "Podiatry")
and service_date between '01 Jan 11' and 31 Dec 11'
Specialty group

This is the table that I want it to look

SPECIALTY Service Packs Total paid £ average spend by SP * < 300 * > 300 *.
Podiatry 129 25682,26 199 * 107 * 22 *.
Podiatry 622 206651,08 332 * 403 * 219 *.

I'm currently running application 10 g

Concerning
Farming :)

First of all, ' 01 Jan 11' is not a date, but rather a string. Use literals date (or at least to_date):

with t as (
           select  specialty,
                   sp_id,
                   sum(payment_total) sp_id_total
             from  a3_fact_sms_service_inv
             where specialty in ('Chiropody','Podiatry')
               and service_date between date '2011-01-01' and date '2011-12-31'
             group by specialty,
                      sp_id
          )
select  specialty,
        count(sp_id) "Service Packs",
        sum(sp_id_total) "Total Paid £",
        round(sum(sp_id_total) / count(sp_id)) "Average Spend per SP",
        count(case when sp_id_total < 300 then 1 end) "Service Packs Less £300",
        count(case when sp_id_total = 300 then 1 end) "Service Packs Equal £300",
        count(case when sp_id_total > 300 then 1 end) "Service Packs Greater £300"
  from  t
  group by specialty
/

SY.

Tags: Database

Similar Questions

  • Update resulted today in count of the number of messages in different folders disappear, except new

    I was asked to update to Thunderbird and did, when I came back later in the afternoon, the messages were always in each folder (sent for example), but the count of the number of messages in each category had disappeared.

    What about the small thing square on the line with the name above the part of the file. He has options for/unread and size

  • How to count from a number

    Hello

    I am recieveing a number between a VI, and I want to count from the number received up to 1.  The number is subject to change.

    If it works for you? Would not need a shift register if you're going to go in order.

    Should be the last iteration (123-122 = 1). Make sure you take into account that it would be 1-based, so if you use the screw of Excel, you will probably need to decrement to be the zero-based index.

    Edit: Do what crossrulz says if your ultimate goal is the release of table, simply load as an array from the outset.

  • Get the letters when I type the number of

    Original title: numeric keys

    why I get letters that appear on the screen when I press the number keys

    Hello

    1. what operating system do you use?

    2 did you change on your computer?

    3. what application you use to type?

    4 are you facing issue while typing online?

    If you use windows7, I suggest you follow the link and check.

    I suggest you to check in safe mode and perform the clean boot and check.

    Step 1:

    Advanced, including safe mode startup options

    http://Windows.Microsoft.com/en-us/Windows7/advanced-startup-options-including-safe-mode

    Step 2:

    How to troubleshoot a problem by performing a clean boot in Windows Vista or in Windows 7

    http://support.Microsoft.com/kb/929135

    Note: After a repair, be sure to set the computer to start as usual as mentioned in step 7 in the above article.

    I also suggest you check for computer\Keyboard manufacturer.

    I also suggest to activate / deactivate the number pad emulation, check the documentation that came with the computer.

    In addition, add toggle button F-lock (locking function).

  • When I try and get the Microsoft Messaging support, he asks me a 20 digit number. When I enter this number, he told me that he is not registered in the country I've selected.

    I have Dell XPS M1330 with windows vista home premium. When I try to get the support of e-mail on the microsoft support site, he asked 20-digit PID number, when I entered that number, it says this PID is not saved in the chosen country, I m from India, I chose India-English. I also tried in the United States, United Kingdom, but whenever he says the same thing. I can't support for the supplied windows pre-loaded with my laptop. I ve the product key and PID number. Pls guide me to do this, my windows is enabled.

    original title: Support of Windows problem

    Reference Dell are responsible for their OEM of Windows versions. Microsoft supports the commercial versions of Windows. I'm not familiar with the details of the software support arrangements, but it is the basis that applies.

    What is the problem?

  • BlackBerry Smartphones Ouch: When I dial a number through address book I no longer get my contact list! 8703 e

    Instead, if Igo to the bar where you enter the name or number and press the wheel I have access to the "addess book call"... I press the wheel, then he goes "use once"... underneath, it reads * no addresses * above appeal when he reads "Personal" and this call:...

    I can not move personal wheel and when I went to companies via the options I am STILL unable to access my address book!

    When I dial a number known... the name is displayed.

    Very frustrating as I have hundreds of names that I have in the book necessary to maintain a school system go!

    And I tried pressing the sym, shift, and other keys to see if that makes a difference... NG

    Looks like a filter can be activated. Address book, click the wheel and go to filter. Clear all that is checked. If none of your contacts are associated with a filter, it's probably why you didn't see anything in the address book

  • I purchased a download version of Lightroom 6 from Amazon and when I write the number of license keys I get this message "we are unable to validate this serial number for adobe Lightroom. Please contact Customer Support. "

    I purchased a download version of Lightroom 6 from Amazon and when I write the number of license keys I get this message "we are unable to validate this serial number for adobe Lightroom. Please contact Customer Support. "

    Contact adobe support by clicking on this link then "still need help" as soon as it appears, https://helpx.adobe.com/contact.html

  • How can I activate an older version of Photoshop that I have loaded on my new tablet? Web activation does not work, and when I call the number, it is said that it is not longer used. In the meantime, I'm up to 13 days until it stops working due to not bei

    How can I activate an older version of Photoshop that I have loaded on my new tablet? Web activation does not work, and when I call the number, it is said that it is not longer used. Meanwhile, I'm 13 days until it stops working due to not be enabled. Help?  I really need to continue to use this product for my home business. It works very well not activated but the threat is that it will stop working in 13 days more if I don't get activated, and none of the activation methods that they list seem to work.

    You can download CS2 if you have a valid license for CS or CS2.

    And you have to follow the instructions and use the download again AND the new serial number.

  • I just disabled adobe acrobat 8.0 standard version of an old laptop in order to install it on my new laptop, but when I enter license number, it tells me it is invalid

    I just disabled adobe acrobat 8.0 standard version of an old laptop in order to install it on my new laptop, but when I enter license number, it tells me it is invalid

    Error "serial number is not valid for this product". Creative Suite

  • Is obstacle cursor when processing a huge number of records?

    Hi all

    I use the slider in my several times stored proc. Is obstacle cursor when processing a huge number of records?
    Is there an alternative way that I can treat the records one by one?

    Thanks and greetings
    Nana Akkivalli.

    IS it your own custom proc? PLSQL has bulk collect ability you should look for large volumes, see this recent article for info;
    http://www.Oracle.com/technetwork/issue-archive/2011/11-may/o31asktom-354139.html

    OWB generates several different code of pure execute SQL based paths in bulk using PLSQL.

    See you soon
    David

  • Added a counter which keeps the total number of times where a loop has run, even if LabVIEW has been restarted.

    Hi all

    I am writing a VI to measure the data and insert into a database. The measures are controlled by a loop that runs once per minute. I want to give a unique to each measure identification number and store it too much in the database.

    To do this, I want to add a counter to this loop so that I can count the number of times that the loop is executed in total. It is, even if the VI, LabVIEW or even e PC is restarted, I want the counter to track the number of executions. If say the Edeka runs twice and then the VI is stopped and restarted, I want the number following on the counter to be three.

    Does anyone have an idea on how to do it? I'm gratefule for any help!

    Clara

    A suggestion. Can you write the last counter value in a txt file and read it all by running again the vi?

  • How do I see the number Total of Hits looking for Windows 7?

    The Windows XP search companion always informed the user the number of visits ("found 50 to date"), even in real time. In Windows 7, it is a confidential information jealously guarded, or so it seems.

    TIA,

    -RFH

    Hi Ray Cambridge,.

    If you want to know the number of files found after research all you have to do is you have to select all the files by pressing on Ctrl + A so that all the files will choose and then on the lower left corner, it will show the total number of files count.

    Hope this information is helpful and let us know if you need more assistance. We will be happy to help.

  • Count of the number of months with unpaid for the last six months

    Hello

    I now table to store the daily presence of each employee

    ATTENDANCESHEET

    EMPID

    PAYROLLDATE

    UNPAID

    1

    10/01/2013

    6

    1

    10/02/2013

    2

    1

    11/01/2013

    0

    1

    11/02/2013

    0

    1

    12/01/2013

    0

    1

    12/02/2013

    0

    1

    01/01/2014

    0

    1

    01/02/2014

    0

    1

    02/01/2014

    0

    1

    02/02/2014

    0

    1

    03/01/2014

    45

    1

    03/02/2014

    0

    2

    03/01/2014

    0

    2

    03/02/2014

    0

    I want to get the number of months used unpaid in the past 6 months (excluding the current).

    If the month of payroll, I'm in treatment is 4, 2014, I spend 4 as payrollmonth and 2014 as payroll year

    The application must check the latest 6 month data and number of months for which there is any unpaid value

    In the case above for month 4, 2014, the power required is

    EmpID

    County

    1

    2

    2

    0

    I use oracle 10g

    EXAMPLES OF DATA

    create the table attendancesheet as

    (

    Select 1 as empid, to_date (January 10, 2013 ',' DD/MM/YYYY ') as payrolldate, 6 paid by union double all the

    Select 1 as empid, to_date (10 February 2013 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the

    Select 1 as empid, to_date (January 11, 2013 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the

    Select 1 as empid, to_date (February 11, 2013 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the

    Select 1 as empid, to_date (12 January 2013 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the

    Select 1 as empid, to_date (February 12, 2013 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the

    Select 1 as empid, to_date (1 January 2014 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the

    Select 1 as empid, to_date (February 1, 2014 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the

    Select 1 as empid, to_date (January 2, 2014 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the

    Select 1 as empid, to_date (February 2, 2014 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the

    Select 1 as empid, to_date (3 January 2014 ',' DD/MM/YYYY ') as payrolldate, 45 paid by union double all the

    Select 1 as empid, to_date (3 February 2014 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the

    Select 2 as empid, to_date (3 January 2014 ',' DD/MM/YYYY ') as payrolldate, 0 as default all the double union

    Select 2 as empid, to_date (3 February 2014 ',' DD/MM/YYYY ') as payrolldate, 0 paid double

    );

    Help, please

    Hello

    So, you want to count the distinct months for 6 months before (not included) the given month; is this fair?

    Here's one way:

    VARIABLE month VARCHAR2 (2)

    Year VARIABLE VARCHAR2 (4)

    EXEC: months: = '4';

    EXEC: year: "2014"; =

    WITH got_end_date AS

    (

    SELECT TO_DATE (: month |) '/' || : year

    , ' MM/YYYY ".

    ) AS end_date

    OF the double

    )

    SELECT a.empid

    , COUNT (DISTINCT

    CASE

    WHEN a.unpaid > 0

    THEN TRUNC (a.payrolldate, 'MONTH')

    END

    ), Cnt

    Of attendancesheet one

    JOIN e-got_end_date WE a.payrolldate > = ADD_MONTHS (e.end_date-6)

    AND a.payrolldate< >

    GROUP BY a.empid

    ORDER BY a.empid

    ;

    If you use a WHERE clause to exclude the lines with some outstanding = 0 (or unpaid is NULL), then you would get no output for employees like empid = 2 in this example.  A WHERE clause ignores an entire line, so I used an expression BOX just a value.

  • How to count the tank &amp; number?

    Hi all

    11.2.0.1

    I have an EMP table with column EMPID (varchar2 (15))

    It contains the values of numbers and characters.

    For example:

    5365

    cllaurena

    6356

    5365

    csroxas

    fstang

    1010

    cuermita

    fstang

    How to count all the digital and all characters, or a group of tank and the number without creating features?

    Thank you all,

    PK

    Are you after something like this?

    WITH t
         AS (SELECT '5365' str FROM DUAL
             UNION ALL
             SELECT 'cllaurena' FROM DUAL
             UNION ALL
             SELECT '6356' FROM DUAL
             UNION ALL
             SELECT '5365' FROM DUAL
             UNION ALL
             SELECT 'csroxas' FROM DUAL
             UNION ALL
             SELECT 'fstang' FROM DUAL
             UNION ALL
             SELECT '1010' FROM DUAL
             UNION ALL
             SELECT 'cuermita' FROM DUAL
             UNION ALL
             SELECT 'fstang' FROM DUAL)
      SELECT CASE
                WHEN LENGTH (TRANSLATE (str, '~0123456789', '~')) IS NULL
                THEN
                   'num'
                ELSE
                   'not_number'
             END
                typ,
             COUNT (*)
        FROM t
    GROUP BY CASE
                WHEN LENGTH (TRANSLATE (str, '~0123456789', '~')) IS NULL
                THEN
                   'num'
                ELSE
                   'not_number'
             END;
    

    TYPE COUNT (*)

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

    num                  4

    not_number 5

    See you soon,.

    Manik.

  • GROUP OF + SQL COUNT + SUM

    Hello

    I have a table, it has 2 colunms, (name, number)

    name number
    B1 7
    B1 7
    B1 28
    B1 28
    B1 28
    B2 7
    B2 28
    B3 7
    . .
    . .
    .
    .


    I want to see below

    number
    name sum 7sum 28sum

    5 2 3 B1
    2 1 1 B2
    B3...
    .
    .
    .
    .
    .


    Can you help me

    THANK YOU VERY MUCH FOR HELP

    Like this?

    SQL> ed
    Wrote file afiedt.buf
    
      1  with t as (select 'B1' as name, 7 as num from dual union all
      2             select 'B1', 7 from dual union all
      3             select 'B1', 28 from dual union all
      4             select 'B1', 28 from dual union all
      5             select 'B1', 28 from dual union all
      6             select 'B2', 7 from dual union all
      7             select 'B2', 28 from dual union all
      8             select 'B3', 7 from dual)
      9  --
     10  -- end of test data - use query below
     11  --
     12  select name
     13        ,count(*)
     14        ,sum(decode(num,7,1,0)) as sum7
     15        ,sum(decode(num,28,1,0)) as sum28
     16  from t
     17  group by name
     18* order by 1
    SQL> /
    
    NA   COUNT(*)       SUM7      SUM28
    -- ---------- ---------- ----------
    B1          5          2          3
    B2          2          1          1
    B3          1          1          0
    

Maybe you are looking for