Min / Max in the subquery

I'm currently doing tests on Oracle, Postgres and MySQL.
However, Oracle returns me "ORA-00934: Group feature is not allowed here" the same query works with others.

The idea is to return first, Min, Max, last prices for one day on a particular ID.
SELECT
  quotes.id,
  min(quotes.received_time) as opening_time,
  (SELECT ask_price FROM "price_quotes" WHERE id=quotes.id AND received_time >=timestamp'2012-12-10 00:00:00' AND received_time < timestamp'2012-12-11 00:00:00' AND received_time=min(quotes.received_time) ) AS opening_price,
  (SELECT received_time FROM "price_quotes" WHERE received_time >=timestamp'2012-12-10 00:00:00' AND received_time < timestamp'2012-12-11 00:00:00' AND id=quotes.id and ask_price=min(quotes.ask_price) LIMIT 1) as min_price_time,
  min(quotes.ask_price) as min_price,
  max(quotes.received_time) as closing_time, 
  (SELECT ask_price FROM "price_quotes" WHERE id=quotes.id AND received_time >=timestamp'2012-12-10 00:00:00' AND received_time < timestamp'2012-12-11 00:00:00' AND received_time=max(quotes.received_time)) as closing_price,
  (SELECT received_time FROM "price_quotes" WHERE received_time >=timestamp'2012-12-10 00:00:00' AND received_time < timestamp'2012-12-11 00:00:00' AND id=quotes.id and ask_price=max(quotes.ask_price) LIMIT 1) as max_price_time,
  max(quotes.ask_price) as max_price
FROM
  "price_quotes" quotes
WHERE
  quotes.received_time >= timestamp'2012-12-10 00:00:00' and quotes.received_time < timestamp'2012-12-11 00:00:00'
  AND quotes.id = 668792
GROUP BY quotes.id ORDER BY quotes.id ;
I tried to use HAVING and pass the query to the place WHERE but no luck.


This is the Create Table:
CREATE TABLE "price_quotes"
(
   id number(8),
   received_time timestamp, 
   mid_price float, 
   bid_price float,
   ask_price float,
   mid_yield float,
   bid_yield float,
   ask_yield float,
   mid_spread float,
   bid_spread float,
   ask_spread float,
   product_id number(8), 
   product_yield float,
   PRIMARY KEY ( id , received_time )
);
Sample data:
INSERT INTO "price_quotes" VALUES ( 668792, timestamp'2012-12-10 08:00:00', 103, 120, 110, 7, 8, 9, 2.100, 3.050, 4.28999, 29, 1.050);
INSERT INTO "price_quotes" VALUES ( 668792, timestamp'2012-12-10 10:00:00', 99, 98, 100, 4, 2, 3, 0.100, 0.050, 0.28999, 24, 0.050);
INSERT INTO "price_quotes" VALUES ( 668792, timestamp'2012-12-10 16:00:00', 100, 99, 101, 5, 3, 4, 0.200, 0.100, 0.29999, 25, 0.100);
INSERT INTO "price_quotes" VALUES ( 668792, timestamp'2012-12-10 17:00:00', 10, 9, 11, 1, 2, 3, 0.210, 0.330, 0.99, 15, 1.100);
Oracle: 11.2.0.1.0

Published by: 986853 on February 7, 2013 12:23

Hello

986853 wrote:
Thanks for the info, I have edited and corrected the post.

Thank you.
Be sure to post the results desired from these sample data.

This is the Create Table:

CREATE TABLE "price_quotes"
(
id number(8),
received_time timestamp, ...

In Oracle, the names of table in double - quotes are a huge pain.
In addition, if you do not need to register the fractions of a second, use DATEs instead of TIMESTAMPs. They are more effective, and there are a lot more built-in features for dealing with DATEs.
Of course, if you're trying to minimize the differences between the databases, which may influence your decision.

Here are the results you want from the given sample data?

`       OPENING    OPENING  MIN_ CLOSING    CLOSING MAX_PRICE   MAX_
     ID _TIME       _PRICE PRICE _TIME       _PRICE _TIME      PRICE
------- ---------- ------- ----- ---------- ------- ---------- -----
 668792 10-DEC-12      110    11 10-DEC-12       11 10-DEC-12    110
        08.00.00.0               05.00.00.0         08.00.00.0
        00000 AM                 00000 PM           00000 AM

Here's a way to recover them with the FIRST and LAST fucntions aggregate:

SELECT       id
,       MIN (received_time)     AS opening_time
,       MIN (ask_price)
           KEEP (DENSE_RANK FIRST ORDER BY received_time)
                                AS opening_price
,         MIN (ask_price)     AS min_price
,       MAX (received_time)     AS closing_time
,       MIN (ask_price)
           KEEP (DENSE_RANK LAST  ORDER BY received_time)
                                AS closing_price
,       MIN (received_time)
           KEEP (DENSE_RANK LAST  ORDER BY ask_price)
                                AS max_price_time
,       MAX (ask_price)     AS max_price
FROM       price_quotes
WHERE       received_time     >= TIMESTAMP '2012-12-10 00:00:00'
AND       received_time <  TIMESTAMP '2012-12-11 00:00:00'
-- AND        id           = 668792
GROUP BY  id
ORDER BY  id
;

Tags: Database

Similar Questions

  • Min/Max for the calculation of depreciation

    Hey guys, I'm looking to find a curve of free vibration damping factor. I'll use the logarithmic decrement method. I understand that I must get the min max of 2 cycles in my FV curve.

    How to 'point' to the different cycles in my curve? IE. I want to get the min/max of the cycle 1 (before disintegration) and then the 6th cycle after.

    Can someone give me advice?


  • Min - Max and the planning of Kanban

    What are the factors or business cases that should be considered in the choice of planning that we should go?
    Any help would be appreciated

    My Client is interested in the above 2 methods

    Thank you
    Mahendra

    It of a broad question and is not easy to answer.
    One major difference is your philosophy.
    Kanban (if properly implemented) is pull based system.
    Min - max is always anxious that is it looks at your current onhand, future demand, future supply and then comes up with a purchase requisition.

    But there is no hard rule.

    Min - max works well when the issue of subinventory is not placed in a compartment. But in a workshop type of situation, you can have an operator goes the CRUDE inventory to get a bucket of screws.
    If you ran min - max on the WIP subinventory, he will think that you have a lot and does not generate a purchase requisition.
    But another operator may require that these screws and it may be out of them. In this case, a Kanban work better because as soon as the first operator took the last nth bucket, Kanban would have triggered the replenishment process.

    Kanban requires you to spend the time to analyze your problems to get to many of bin sizes and locations.

    The general rule is that Min - Max is simpler to implement.
    Kanban is a bit more complicated. So if your organization is not not mature enough or requires a simpler solution, min - max will work better.

    Sandeep Gandhi

  • Strange behavior with MIN MAX at the same time.

    Hi all

    I had a large table of 5100 K records. I created a Unique Index on a column:

    CREATE UNIQUE INDEX TRANS_ID_IDX on TRANS (TRANS_ID);

    When I asked the Table with this these two applications:

    Select min (trans_id) in trans;
    Select max (trans_id) in trans;

    The execution Plan shows INDEX FULL SCAN (MIN/MAX) and the performance is really quickly (0.01 sec) because the optimizer chooses get the value of the index, of course.

    But now, if I ask the table with two operators:

    Select max (trans_id), min (trans_id) in trans;

    I got:

    TABLE ACCESS FULL and indeed it's really slow to get my answer (9 seconds).

    Even if they are shown a suspicion in my request, it does not:

    Select / * + INDEX (TRANS TRANS_ID_IDX) * / max (trans_id), minutes (trans_id) from trans; == > always TABLE FULL ACCESS!

    So why the optimizer does not use INDEX FULL SCAN (MIN/MAX) to the query when the min and max are both both in the query?

    My database is 11.1.0.7 (with the last batch of patches) on Win XP

    Concerning

    SomeoneElse says:
    ... My order_line_detail table has about 42 M lines. order_line_detail_id is the primary key.
    ..

    Primary key does the trick here, or even NOT NULL column definition.

    SQL> drop table dingostar;
    
    Table dropped.
    
    SQL> create table dingostar (id number);
    
    Table created.
    
    SQL> insert into dingostar select rownum as id from dual connect by level <= 5000;
    
    5000 rows created.
    
    SQL> create index dingostar_idx on dingostar(id);
    
    Index created.
    
    SQL> explain plan for
      2  select max(id),min(id) from dingostar;
    
    Explained.
    
    SQL> select * from table(dbms_xplan.display);
    
    PLAN_TABLE_OUTPUT
    ---------------------------------------------------------------------------------------
    Plan hash value: 1182922403
    
    --------------------------------------------------------------------------------
    | Id  | Operation          | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT   |           |     1 |    13 |     5   (0)| 00:00:01 |
    |   1 |  SORT AGGREGATE    |           |     1 |    13 |            |          |
    |   2 |   TABLE ACCESS FULL| DINGOSTAR |  5000 | 65000 |     5   (0)| 00:00:01 |
    --------------------------------------------------------------------------------
    
    Note
    -----
       - dynamic sampling used for this statement
    
    13 rows selected.
    
    SQL>
    SQL> drop table dingostar;
    
    Table dropped.
    
    SQL> create table dingostar (id number primary key);
    
    Table created.
    
    SQL> create index dingostar_idx on dingostar(id);
    create index dingostar_idx on dingostar(id)
                                            *
    ERROR at line 1:
    ORA-01408: such column list already indexed
    
    SQL> insert into dingostar select rownum as id from dual connect by level <= 5000;
    
    5000 rows created.
    
    SQL> explain plan for
      2  select max(id),min(id) from dingostar;
    
    Explained.
    
    SQL> select * from table(dbms_xplan.display);
    
    PLAN_TABLE_OUTPUT
    ---------------------------------------------------------------------------------------
    Plan hash value: 528434344
    
    -------------------------------------------------------------------------------------
    | Id  | Operation             | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
    -------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT      |             |     1 |    13 |     5   (0)| 00:00:01 |
    |   1 |  SORT AGGREGATE       |             |     1 |    13 |            |          |
    |   2 |   INDEX FAST FULL SCAN| SYS_C007051 |  5000 | 65000 |     5   (0)| 00:00:01 |
    -------------------------------------------------------------------------------------
    
    Note
    -----
       - dynamic sampling used for this statement
    
    13 rows selected.
    
    SQL>
    SQL> drop table dingostar;
    
    Table dropped.
    
    SQL> create table dingostar (id number not null);
    
    Table created.
    
    SQL> create index dingostar_idx on dingostar(id);
    
    Index created.
    
    SQL> insert into dingostar select rownum as id from dual connect by level <= 5000;
    
    5000 rows created.
    
    SQL> explain plan for
      2  select max(id),min(id) from dingostar;
    
    Explained.
    
    SQL> select * from table(dbms_xplan.display);
    
    PLAN_TABLE_OUTPUT
    ---------------------------------------------------------------------------------------
    Plan hash value: 2124830711
    
    ---------------------------------------------------------------------------------------
    | Id  | Operation             | Name          | Rows  | Bytes | Cost (%CPU)| Time     |
    ---------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT      |               |     1 |    13 |     5   (0)| 00:00:01 |
    |   1 |  SORT AGGREGATE       |               |     1 |    13 |            |          |
    |   2 |   INDEX FAST FULL SCAN| DINGOSTAR_IDX |  5000 | 65000 |     5   (0)| 00:00:01 |
    ---------------------------------------------------------------------------------------
    
    Note
    -----
       - dynamic sampling used for this statement
    
    13 rows selected.
    
    SQL>
    

    Nicolas.

  • Can we use the two Min max and MRP element


    Hello

    We can user Min max and the MRP of planning for the element in the same Org (11.5.10.2)

    Thanks in advance

    Ravi

    Hi Ravi,

    There are no restrictions such as a... but it would be an unnecessary activity.

    If your release to users even planned orders by mistake... you would create duplicate supplies.

    Is there any need specific job for which you want to use both of these methods of planning as a whole?

    Kind regards

    Mohan Balaji

  • Connection pool with the OAS and the optimal value of min/max

    Hello world


    I have ", works with admin app to implement under oracle application server connection pool. The current value is min = 0, max = unlimited which I think means not implemented connection pool.

    Anyway I don't have a lot of information on connection pooling, I searched the forums, but I'm not able to find any useful information.


    My Manager would like to know what is the optimal value for min/max for the database, is there a specific formula or a tool that can help me on this issue?


    Thanks in advance.

    Hello

    It's a specific formula or a tool that can help me on this issue?

    The value that you specify for the number of connections and connections Min depends on a combination of factors, including the size and configuration of your database server and the type of the SQL operations that
    your application runs.

    For connection pooling,.
    First, check what is the value of 'process' located on the end of DB (for your current value, check v$ resource_limit at the end of db)...
    for example if the process is set to "1000", you cannot set the maximum value of the connection pool to the end server application above 1000 it will crash your database.

    now on the server side Application.
    As a best practice, set the maximum number of open connections and Minimum of connections open to the same value.

    For more details on connection pool and its settings.
    Check "Setting Up Data Sources - Performance Issues" of the link pdf below

    docs.oracle.com/cd/B14099_19/core.1012/b14001.pdf

    Hope that it would be useful

    Concerning
    Fabian

  • Requests for details of the seller for a Min Max

    Hi all
    When Max Min trigger interface requisition lines, we must get the seller details also filled.
    This has put in place to get these. Because when I run a Min - Max planning report, I don't get the details of the seller.
    We have, in fact, we have one with one provider and the location of the seller
    Help, please.

    OK so everything sounds good... can you confirm that created requisitions (once this audit is performed) are triggered by the execution of State Min - Max. You can check these below 2 audits

    (1) type of source req will be Inv

    (2) the date of creation request must match with your execution time of State mini-maxi and the item, qty should be report to article output values and Reorder Qty

  • Planning of the Min - Max

    Dear Experts
    Min - max planning I put planning should be min - max and min and max quantitiesare (100 to 500) and the order quantity minimum and maximum (100 and 500)
    and entry to the sourcing type I need to know how it will work
    (1) if I put the source as the inventory we give orgainzation and void / inv here will trigger internal requisition?
    (2) if I put the source as provider requires purchase will increase?
    (3) if I put the source as Subinventory works min max is it restore lying displacement order works?

    Thanks in advance

    (1) Yes - run the report of min - max with the Min - Max level organization planning
    (2) Yes - run the report of min - max with the Min - Max level organization planning
    (3) Yes - run the mini-maxi with Subinventory level mini-maxi planning report

  • Sourcing rule works with min - max?

    Hello

    (1) Will Sourcing rule works with min - max planning? How?

    (2) and how you decide who use elements of planning elements u and wich Min - max, to the point of replenishment of development?

    Published by: 832641 on February 4, 2011 19:35

    (1) Yes, sourcing will work in the same way that it works with other sources such as kanban, etc. of the PSO. You must define the ASL for the rule point and sourcing with the corresponding transfer game.

    (2) according to my understanding logically point re - order is nothing but Min - Max, min, and max equal to Min value of the stock you want to maintain for the item

  • Min - Max planning of simple questions

    Hello
    I try to use Min - Max planning. The user guide of the inventory indicating that Min - Max Plannig uses a request to assess the order quantity, but do not say if such request per month, year or whatever. Looking for the numbers seems to be the annual demand (but does not match my annual turnover). What kind of request is used?
    If demand is calculated on an annual basis, order quantity resulting should be to meet the sales of an entire year (I guess).
    Is it possible to change this? Does really matter?

    Please a few words of counsel
    Oscar

    OPR wrote:
    Hello
    I try to use Min - Max planning. The user guide of the inventory indicating that Min - Max Plannig uses a request to assess the order quantity, but do not say if such request per month, year or whatever. Looking for the numbers seems to be the annual demand (but does not match my annual turnover). What kind of request is used?

    Hi Oscar,.
    According to what level (organization or subinventory) you run mini-maxi planning and the options selected for the net demand will determine which will appear under the open request. Open total demand, or before the application deadline, a selection net demand for reserved and unreserved orders and ONGOING work. It is NOT a month, year or no matter what time.

    Min - Max at the organization level:
    If you choose Yes for net without reservation orders, booked net orders and request for net WIP then open application is the sum of full orders, inventory (including orders reserved) reservations, account question move commands and application component WIP scheduled for issue on or before the application deadline.

    Min - Max in the Subinventory level:
    If you choose Yes for orders without reserve Net and Net booked (without WIP request option here), then open the request matches the sum of reserves inventory (including reserved orders), account number move orders and transfer subinventory move orders to demand because of this subinventory or before the power demand
    Date. Reservations subinventory level inventory referencing a different subinventory, or with no specified subinventory, are not included.

    for example if the application deadline is June 30, 2009 and net options have been included as Yes and then he's going to pick up the order until June 30, 2009 (Note: some applications reports have part time question while comparing dates, so in these cases, 30 June 2009 is taken as 30 June 2009 00:00:00 i.e June 29, 2009 midnight!).

    Also if you specify a past date for the cut in demand date, that it would consider open requires available, if necessary, until this last date (but you plan for the future, not past).

  • I have version 29.0.1 and frequently the top right three boxes (min, max, quit) are missing. How should I do?

    Since the installation of version 29, I had this problem where the three boxes are missing. It happens sometimes that I start FireFox. I can right-click in the min, max or closing of FireFox and area. I never had the problem before. I have an i7 processor and on Windows 7.

    The boxes are not visible (i.e., they show a ToolTip if you hover and work if the click in this area) or whatever should not happen at all?

    You can check the problems caused by a corrupt localstore.rdf file.

    You can check for problems with preferences.

    Delete a possible user.js file and files numbered prefs-# .js and rename (or delete) the file prefs.js to reset all the prefs by default, including the prefs set via user.js and pref which is no longer supported in the current version of Firefox.

  • FF9 - hide window control buttons in the title bar (min, max, close) with userchrome.css?

    I use FF9. I userscript.css hide app titlebar button and orange, but the buttons control window always visible! I can't find the script working.

    I don't need min-max-closing button and used to hide if possible without extension.

    Here's screenshort:
    http://s018.Radikal.ru/i522/1201/50/f6a6ea445507.jpg

    If you use the full screen mode and you have these buttons on the Navigation bar, then you should use this code.

    #window-controls { display:none!important; }
  • Table Max &amp; Min is not the first maximum

    Hello

    I develop for NI USRP OFDM system and I'm doing the Schmidl-Cox algorithm for frame and frequency offset correction. At some point, I need to find the index of the first maximum in a table. This table has a growing value until it reaches 1 and remains constant. The first 1 occurs in position 12. But the output I'm getting to the table Max & Min block is 76. It is neither the first nor the last 1 in this table. And I don't know why I get the bad clue.

    Anyone know this kind of situation before?

    You can attach a small example that contains your table as a constant of diagram?

    My guess is values differ even in very small amounts. Try to show at least 14 digits, depending on the data type.

    What happens if you subtract the max found the table? Previous results are very slightly negative?

  • Get the date range min/max for consecutive events.

    Hi all...

    I am fairly new to the programming of the DB and is working on some examples I picked up a few places. The database version is 10g R2.

    I would like to configure the data here and I can explain my requirement.

    create table table_1
    (product_id varchar2(25),
    region_id  number,
    event_id number
    event_date date,
    event_status number(1))
    /
    
    
    

    Now the data because it is->

    insert into table_1 values ('Prod-1',10, null, to_date('01-feb-2014','dd-mon-yyyy'),null)
    /
    insert into table_1 values('Prod-1',10, 1001, to_date('10-mar-2014','dd-mon-yyyy'), 1)
    /
    insert into table_1 values('Prod-1',10, 1001, to_date('20-mar-2014','dd-mon-yyyy'), 3)
    /
    insert into table_1 values('Prod-1',10,1002, to_date('01-apr-2014','dd-mon-yyyy'), 1)
    /
    insert into table_1 values('Prod-1',10, 1002, to_date('10-apr-2014','dd-mon-yyyy'), 3)
    /
    commit
    /
    
    
    
    

    If the table now contains the following data

    select * from table_1; 
    
    
    

    PRODUCT_ID REGION_ID EVENT ID EVENT_DAT EVENT_STATUS

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

    Prod-1 10 1 February 14

    Prod-1 10 1001 10 March 14 1

    Prod-1 10 1001 20 March 14 3

    Prod-1 10 1002 1 April 14 1

    Prod-1 10 1002 April 10, 14 3

    Now, the condition is as follows:

    Above is the dates start and end for the tests on a product in a given region. The event_status column indicates the dates of beginning and end. Event_status = 1, for the date of beginning and the event_status = 3 of the end date.

    A new event is now coming from March 21 and ending on March 31.

    The power required is a product identifier / region; If there are events that are ending and then count the days, for example, 1001 to end on March 20, but now the new event begins on 21 March... and the new event ends on 31 March and event 1002 begins 01 - Apr... and so on.

    The output required for this is as follows:

    PRODUCT_ID REGION_ID EVENT_MIN_DATE EVENT_MAX_DATE

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

    Prod-1 10 10 14 March 10 April 14

    The output should give a product identifier / region, when events are immediately after the other, out the min date of beginning and end of max for all these manifestations of "back to back".

    Now I wrote the code for this, but it goes into a purely 'loop' for application in PLSQL... But my head tells me that if the results are correct. the PLSQL implementation is not the most efficient and effective way.

    Can someone help me to form the query? I tried to use functions analytical min/max but it gives me the start and end dates back even if my events are not "back to back" or previous/succeed each other... so my query result is not quite correct.

    Am reading on the TYPE clause but would be grateful if someone could help me with this query... or any other form better to implement this event so PLSQL can be used. The database version is 10g R2.

    Thank you

    K

    PS - The number of such events back to back is limited to 4 and the events could be created in any order. But if someone could help me with the scenario above; am sure I could make a request addressed to any change in the order. :-)

    No this isn't a recursive with clause, perhaps the UNION ALL you got confused. She will work with 10g.

    Since there are 2 tables that you said, the block all_data brings together only the lines of the two tables. table_1 start_date and end_date are built from the event_status (where the max in group by).

  • Impossible to get Min, Max and median of the values in the date range values

    Hello

    I had a requirement as to show the data of each charge group of wise men as '< 100' ' 100-199 "" 200-299 "" 300-399 "400-499, 500-599 600-699 700-799 800-899 900-999 > = 1000 '"»

    With the query be able to get the count between the beach and the total below. But impossible to get the Min and Max values for this range. For example if the County < 100 is 3 then in these 3, the lowest value is need to display in the min. Idem for Max column also.

    In the light of the median value on these values.

    Thanks in advance.



    Requirement is as below:
    State < 100 100-199, 200-299 300-399 400-499, 500-599 600-699 700-799 800-899 900-999 > = 1000 Min Total median Max
    AK 1 2 0 4 1 4 4 35 35 4 1 $25 $85 850 $1,200
    AL 0 0 2 27 10 17 35 2 2 35 0 $103 100-$1 500 750


    * "QUERY ' * '"

    WITH t AS
    (SELECT 'AL' State, 12 DUAL FROM VALUE
    UNION ALL
    SELECT 'AL' State, 67 FROM DUAL VALUE
    UNION ALL
    SELECT 'AL' State, 23 FROM DUAL VALUE
    UNION ALL
    SELECT 'AL' State, 12 DUAL FROM VALUE
    UNION ALL
    SELECT 'AL' State, 12 DUAL FROM VALUE
    UNION ALL
    SELECT 'AL' State, 78 FROM DUAL VALUE
    UNION ALL
    SELECT 'AL' State, 34 FROM DUAL VALUE
    UNION ALL
    SELECT 'AL' State, 4 DUAL FROM VALUE
    UNION ALL
    SELECT 'AL' State, 12 DUAL FROM VALUE
    UNION ALL
    SELECT 'AL' State, 15 VALUE FROM DUAL
    UNION ALL
    SELECT "AZ" State, FROM DUAL VALUE 6
    UNION ALL
    SELECT "AZ" State, 123 FROM DUAL VALUE
    UNION ALL
    SELECT "AZ" State, 123 FROM DUAL VALUE
    UNION ALL
    SELECT 'MY' State, 23 FROM DUAL VALUE
    UNION ALL
    SELECT 'MY' State, 120 FROM DUAL VALUE
    UNION ALL
    SELECT 'MY' State, 456 FROM DUAL VALUE
    UNION ALL
    SELECT 'MY' State, 11 FROM DUAL VALUE
    UNION ALL
    SELECT 'MY' State, 24 FROM DUAL VALUE
    UNION ALL
    SELECT 'MY' State, 34 FROM DUAL VALUE
    UNION ALL
    SELECT 'MY' State, 87 DUAL FROM VALUE
    UNION ALL
    SELECT 'MY' State, 23 FROM DUAL VALUE
    UNION ALL
    SELECT 'MY' State, 234 DUAL FROM VALUE
    UNION ALL
    SELECT 'MY' State, 789 FROM DUAL VALUE
    UNION ALL
    SELECT "HD" State, VALUE FROM DUAL 54321).
    -End of test data
    AS T1
    (SELECT State,
    NVL (COUNT (DECODE (VALUE, 0, 0)), 0) '< 100 ',.
    NVL (COUNT (DECODE (VALUE, 1, 1)), 0) '100-199.
    NVL (COUNT (DECODE (VALUE, 2, 2)), 0) '200-299.
    NVL (COUNT (DECODE (VALUE, 3, 3)), 0) '300-399.
    NVL (COUNT (DECODE (VALUE, 4, 4)), 0) '400-499.
    NVL (COUNT (DECODE (VALUE, 5, 5)), 0) '500-599,'
    NVL (COUNT (DECODE (VALUE, 6, 6)), 0) '600-699.
    NVL (COUNT (DECODE (VALUE, 7, 7)), 0) '700-799.
    NVL (COUNT (DECODE (VALUE, 8, 8)), 0) '800-899.
    NVL (COUNT (DECODE (VALUE, 9, 9)), 0) '900-999. "
    NVL (COUNT (DECODE (VALUE, 10, 10)), 0) ' > = 1000.
    (SELECT STATE,
    CASE
    WHAT VALUE < 100 THEN 0
    WHAT A VALUE BETWEEN 100 AND 199 THEN 1
    WHAT VALUE BETWEEN 200 AND 299, THEN 2
    WHAT VALUE BETWEEN 300 AND 399 THEN 3
    WHAT VALUE BETWEEN 400 AND 499 THEN 4
    WHAT VALUE BETWEEN 500 AND 599 5 THEN
    WHAT VALUE BETWEEN 600 AND 699 6 THEN
    WHAT VALUE BETWEEN 700 AND 799 THEN 7
    WHAT VALUE BETWEEN 800 AND 899 8 THEN
    WHAT VALUE FROM 900 TO 999 9 THEN
    WHAT VALUE > = 10 THEN 1000
    END
    VALUE
    T)
    GROUP BY State)
    SELECTION STATE,
    "< 100."
    "100-199.
    "200 299",
    "300-399.
    "400-499.
    '500-599,'
    "600-699.
    "700-799.
    "800-899.
    "900-999."
    "> = 1000."
    '< 100 '.
    + "100-199.
    + "200-299.
    + '300-399.
    + '400-499.
    + "500-599.
    + '600-699.
    + "700-799.
    + "800-899.
    + '900-999 ".
    + ' > = 1000.
    in total,.
    less ("< 100",)
    "100-199.
    "200 299",
    "300-399.
    "400-499.
    '500-599,'
    "600-699.
    "700-799.
    "800-899.
    "900-999."
    ("> = 1000 ') min_val,.
    largest ("< 100",)
    "100-199.
    "200 299",
    "300-399.
    "400-499.
    '500-599,'
    "600-699.
    "700-799.
    "800-899.
    "900-999."
    ("> = 1000 ') max_val
    FROM t1
    /

    Why not keep it simple?

    WITH t AS
    (SELECT 'AL' state, 12 VALUE FROM DUAL
    UNION ALL
    SELECT 'AL' state, 67 VALUE FROM DUAL
    UNION ALL
    SELECT 'AL' state, 23 VALUE FROM DUAL
    UNION ALL
    SELECT 'AL' state, 12 VALUE FROM DUAL
    UNION ALL
    SELECT 'AL' state, 12 VALUE FROM DUAL
    UNION ALL
    SELECT 'AL' state, 78 VALUE FROM DUAL
    UNION ALL
    SELECT 'AL' state, 34 VALUE FROM DUAL
    UNION ALL
    SELECT 'AL' state, 4 VALUE FROM DUAL
    UNION ALL
    SELECT 'AL' state, 12 VALUE FROM DUAL
    UNION ALL
    SELECT 'AL' state, 15 VALUE FROM DUAL
    UNION ALL
    SELECT 'AZ' state, 6 VALUE FROM DUAL
    UNION ALL
    SELECT 'AZ' state, 123 VALUE FROM DUAL
    UNION ALL
    SELECT 'AZ' state, 123 VALUE FROM DUAL
    UNION ALL
    SELECT 'MA' state, 23 VALUE FROM DUAL
    UNION ALL
    SELECT 'MA' state, 120 VALUE FROM DUAL
    UNION ALL
    SELECT 'MA' state, 456 VALUE FROM DUAL
    UNION ALL
    SELECT 'MA' state, 11 VALUE FROM DUAL
    UNION ALL
    SELECT 'MA' state, 24 VALUE FROM DUAL
    UNION ALL
    SELECT 'MA' state, 34 VALUE FROM DUAL
    UNION ALL
    SELECT 'MA' state, 87 VALUE FROM DUAL
    UNION ALL
    SELECT 'MA' state, 23 VALUE FROM DUAL
    UNION ALL
    SELECT 'MA' state, 234 VALUE FROM DUAL
    UNION ALL
    SELECT 'MA' state, 789 VALUE FROM DUAL
    UNION ALL
    SELECT 'MH' state, 54321 VALUE FROM DUAL)
    SELECT state
         , NVL( COUNT( case when VALUE < 100 then 0 end ), 0 ) "<100"
         , NVL( COUNT( case when VALUE between 100 and 199 then 0 end ), 0 ) "100-199"
         , NVL( COUNT( case when VALUE between 200 and 299 then 0 end ), 0 ) "200-299"
         , NVL( COUNT( case when VALUE between 300 and 399 then 0 end ), 0 ) "300-399"
         , NVL( COUNT( case when VALUE between 400 and 499 then 0 end ), 0 ) "400-499"
         , NVL( COUNT( case when VALUE between 500 and 599 then 0 end ), 0 ) "500-599"
         , NVL( COUNT( case when VALUE between 600 and 699 then 0 end ), 0 ) "600-699"
         , NVL( COUNT( case when VALUE between 700 and 799 then 0 end ), 0 ) "700-799"
         , NVL( COUNT( case when VALUE between 800 and 899 then 0 end ), 0 ) "800-899"
         , NVL( COUNT( case when VALUE between 900 and 999 then 0 end ), 0 ) "900-999"
         , NVL( COUNT( case when VALUE >= 1000 then 0 end ), 0 ) ">=100"
         , count( value ) "total"
         , min( VALUE ) "min"
         , max( VALUE ) "max"
         , avg( VALUE ) "avg"
         , median( value ) "median"
    from t
    group by state
    

Maybe you are looking for