Greatest and Max in sql

greatest means it take the high value frm the exprn,,,,isnt it?
so in this eg: SELECT greatest('22', '5', '60', '1000','1') FROM DUAL;----------Ans is : *60*
select GREATEST('aby', 'john', 'faisal') from dual; --------Ans is john
how it get these outputs outut,,pls help me
and how to find the greatest or higest date from one table using greatest function,
pls explain with an example
thnz
Edited by: 821553 on May 17, 2011 3:16 PM
Edited by: 821553 on May 17, 2011 3:23 PM

821553 wrote:
bt i didnt understand yet that how it get the answer '60'
select GREATEST('aby', 'john', 'faisal') from dual; --------Ans is john
how it get these outputs?/how it compare the two charctersIf you look at how the data is stored internally...
SQL> ed
Wrote file afiedt.buf
  1  with t as (select 'aby' as nm from dual union all
  2             select 'john' from dual union all
  3             select 'faisal' from dual)
  4  --
  5  -- end of test data
  6  --
  7  select nm, dump(nm) as dump_nm
  8* from t
SQL> /
NM     DUMP_NM
aby    Typ=1 Len=3: 97,98,121
john   Typ=1 Len=4: 106,111,104,110
faisal Typ=1 Len=6: 102,97,105,115,97,108
SQL>You can see that the bytes representing each characters have numeric values, and it each of these that are compared from left to right. 'john' starts with a 'j' which is 106 and that's greater than 97 or 102, so john is the greatest.
If there were two names beginning with 'j' then the next character is compared...
SQL> ed
Wrote file afiedt.buf
  1  with t as (select 'aby' as nm from dual union all
  2             select 'john' from dual union all
  3             select 'jon' from dual union all
  4             select 'faisal' from dual)
  5  --
  6  -- end of test data
  7  --
  8  select nm, dump(nm) as dump_nm
  9* from t
SQL> /
NM     DUMP_NM
aby    Typ=1 Len=3: 97,98,121
john   Typ=1 Len=4: 106,111,104,110
jon    Typ=1 Len=3: 106,111,110
faisal Typ=1 Len=6: 102,97,105,115,97,108In this example we have two names beginning "j" which is the greatest of the first character, so the second character is looked at, and there is still two names because they both have the character "o", so it's the 3rd character that is looked at with "h" (104) being compared to "n" (110) to determine that "jon" is the greatest....
SQL> select greatest('aby','john','jon','faisal') from dual;
GRE
jon
SQL>

Similar Messages

  • How to retrieve Min(startDate) and Max(endDate) for different groups of data? (sql server 2000)

    My sample dataset (below) contains 3 groups -- 'a', 'b', 'c'.  I need to retrieve the Min(startDate) and Max(EndDate) for each group so that the output looks something like this (date format not an issue):
    fk   minStart       maxEnd
    a    1/13/1985    12/31/2003
    b    2/14/1986    12/31/2003
    c    4/26/1987    12/31/2002
    What is the Tsql to perform this type of operation?  Note:  the actual data resides in a sql server 2000 DB.  If the Tsql is different between version 2000 and the later versions -- I would be grateful for both versions of the Tsql
    --I noticed that multiple lines of Insert values doesn't work in Sql Server 2000 -- this sample is in Sql Server 2008
    create table #tmp2(rowID int Identity(1,1), fk varchar(1), startDate datetime, endDate datetime)
    insert into #tmp2
    values
    ('a', '1/13/1985', '12/31/1999'),
    ('a', '3/17/1992', '12/31/1997'),
    ('a', '4/21/1987', '12/31/2003'),
    ('b', '2/14/1986', '12/31/2003'),
    ('b', '5/30/1993', '12/31/2001'),
    ('b', '6/15/1994', '12/31/2003'),
    ('b', '7/7/2001', '12/31/2003'),
    ('c', '4/26/1987', '12/31/1991'),
    ('c', '8/14/1992', '12/31/1998'),
    ('c', '9/10/1995', '12/31/2002'),
    ('c', '10/9/1996', '12/31/2000')
    Thanks
    Rich P

    Rich
    It is unclear what you are trying to achieve, you said that it is SQL Server 2000 but provide a sample data with SQL Server 2008 syntax
    Is it possible to use UNION ALL for your queries to make its one 
    select * from
    select * from #tmp2 t1 where exists
    (select * from (select top 1 * from #tmp2 t2 where t2.fk = t1.fk order by t2.startdate) x where x.rowID = t1.rowID)
    UNION ALL
    select * from #tmp2 t1 where exists
    (select * from (select top 1 * from #tmp2 t2 where t2.fk = t1.fk order by t2.Enddate desc) x where x.rowID = t1.rowID)
     as  der order by fk
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Performance Issue using min() and max() in one SQL statement

    I have a simple query that selects min() and max() from one column in a table in one sql statment.
    The table has about 9 Million rows and the selected column has a non unique index. The query takes 10 secs. When i select min() and max() in separate statements, each takes only 10 msecs:
    This statement takes 10 secs:
    select min(date_key) , max(date_key)
    from CAPS_KPIC_BG_Fact_0_A
    where date_key != TO_DATE(('1900-1-1' ),( 'YYYY-MM-DD'))
    This statement takes 10 msecs:
    select min(date_key)
    from MYTABLE
    where date_key != TO_DATE(('1900-1-1' ),( 'YYYY-MM-DD'))
    union all
    select max(date_key) from MYTABLE
    Because the first statement is part of an autmatic generated SQL of an application, i can't change it and i have to optimize the data model. How can i speed up the first statement?

    I've ran similar query on a table that has 10 milliion rows, with an index on the date column
    This is what I have found:
    SQL> set timing on
      1  SELECT MIN(ID_DATE) MIN_DATE, MAX(ID_DATE) MAX_DATE
      2      FROM MY_DATE
      3*     WHERE ID_DATE != TO_DATE(('1900-1-1' ),( 'YYYY-MM-DD'))
    SQL> /
    MIN_DATE  MAX_DATE
    03-APR-76 06-JAN-02
    real: 43383
    SQL> SELECT MIN(ID_DATE) MIN_DATE FROM MY_DATE
      2   WHERE ID_DATE != TO_DATE(('1900-1-1' ),( 'YYYY-MM-DD'))
      3  UNION ALL
      4  SELECT MAX(ID_DATE) MAX_DATE FROM MY_DATE
      5   WHERE ID_DATE != TO_DATE(('1900-1-1' ),( 'YYYY-MM-DD'))
      6  /
    MIN_DATE
    03-APR-76
    06-JAN-02
    real: 20
    SQL> SELECT MIN_DATE, MAX_DATE FROM
      2  (SELECT MAX(ID_DATE) MAX_DATE FROM MY_DATE
      3  WHERE ID_DATE != TO_DATE(('1900-1-1' ),( 'YYYY-MM-DD')) ) A,
      4  (SELECT MIN(ID_DATE) MIN_DATE FROM MY_DATE
      5  WHERE ID_DATE != TO_DATE(('1900-1-1' ),( 'YYYY-MM-DD')) ) B
      6  /
    MIN_DATE  MAX_DATE
    03-APR-76 06-JAN-02
    real: 10
    SQL> My conculsion, there is nothing you can do to the tables that will improve that particular statement.
    Why can't you modify the application?

  • Transactions between Min and Max dates

    Hey all,
    I have a requirement to extract data between min(transdate) and max(transdate), i got to do this using a single query, i used two queries, ie. 1 select for selecting the max and min dates and my second query to get the transactions. Can some one give me an idea to solve this, as Max & Min functions are not allowed in the where clause.
    Thanks in Advance
    - Eric

    Why single fetch if you want effeciency then use analytic function
    SQL> SELECT empno,ename,hiredate FROM
      2  (SELECT empno,ename,hiredate,MAX(hiredate) OVER (ORDER BY empno) m,
      3          MIN(hiredate) OVER (ORDER BY empno) mi FROM emp)
      4  WHERE hiredate BETWEEN mi AND m;The least and greatest function returns the smallest and greatest value in a list of expressions.
    The syntax for the least function is:
    least( expr1, expr2, ... )
    Khurram

  • SharePoint - Error_1_Error occurred in deployment step 'Add Solution': Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was rea

    Hi,
    I am Shanmugavel, SharePoint developer, 
    I am facing the below SharePoint 2013 deployment issue while deploying using VS2012.
    If i will deploy the same wsp or existing wsp
    (last build) using direct powershell deployment, the solution adding properly, but the same timeout exception coming while activation the features.  Please find the below error.
    I tried the below activists:
    1. Restarted my dev server, DB server. 
    2. tried the same solution id different server
    3. tried existing wsp file (last build version)
    4. Deactivated all the features, including project Active deployment configuration.... but still i am facing the same issue.
    I hope this is not coding level issue, because still my code is not start running, before that some problem coming.
    Please help me any one.....  Last two days i am struck because of this...

    What you need to understand is the installation of a WSP does not do much. It just makes sure that you relevant solution files are deployed to the SharePoint farm.
    Next comes the point when you activate the features. It is when the code which you have written to "Activate" certain features for your custom solution.
    Regarding the error you are getting, it typically means that you have more connections (default is I guess 100) open for a SQL database then you are allowed to.
    If you have a custom database and you are opening a connection, make sure you close it as well.
    Look at the similar discussion here:
    The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool
    size was reached[^]
    I would suggest further to look at the
    ULS logs[^] to get better insight.
    Manas Bhardwaj's Stream : www.manasbhardwaj.net

  • Min and max constraints

    In my database design and implementation module I'm at the implementation stage. I've set up all of my tables with PK and FK constraints and I'm wondering if you can enforce min and max column constraints. One of the rules of my DB is for my staff table there has to be a minimum of 10 and a maximum of 50, how would I enforce this rule as a constraint on the staff table or isn't this possible?
    We have only been learning database design and SQL fundamentals so I don't think I'd be allowed to use triggers or procedures.
    Many thanks
    Mike

    mharper wrote:
    thanks guys these commands were accepted
    alter table staff
    add constraint chk_staff_max check (staff_id <= 50);
    alter table staff
    add constraint chk_staff_min check (staff_id >= 10);
    Thing is my staff_id's are in the format 'S110001' will these constraints only check for integers 10 - 50? maybe I need to use a count function on the column or something?
    thanks again for your help!
    MikeCheck constraint can also be used to check a list of values.
    example:
    ALTER TABLE <table_name>
    ADD CONSTRAINT <constraint_name>
    CHECK (<column_name> LIKE <condition>);
    ALTER TABLE <table_name>
    ADD CONSTRAINT <constraint_name>
    CHECK (<column_name> NOT LIKE <condition>);
    ALTER TABLE <table_name>
    ADD CONSTRAINT <constraint_name>
    CHECK (<column_name>
    IN (<comma delimited list of values>);
    ALTER TABLE <table_name>
    ADD CONSTRAINT <constraint_name>
    CHECK (<column_name>
    NOT IN (<comma delimited list of values>);
    ALTER TABLE <table_name>
    ADD CONSTRAINT <constraint_name>
    CHECK (<column_name> BETWEEN <lower_value>
    AND <higher_value>);
    ALTER TABLE <table_name>
    ADD CONSTRAINT <constraint_name>
    CHECK (<column_name>
    NOT BETWEEN <lower_value> AND <higher_value>);
    ALTER TABLE <table_name>
    ADD CONSTRAINT <constraint_name>
    CHECK (<column_name>) > (<condition>);

  • Parallel_max_server  and max process

    Hi,
    is there any initial parameter like : max process ?
    is there any relation between parallel_max_server  and max process ?
    I can not understand the last post of the followin thread :
    Getting error in TNS connection from Oracle hosted on LINUX machine
    I have the same TNS_12564 error.
    Thanks.

    Mines are :
    SQL> show parameter process
    NAME                                 TYPE        VALUE
    processes                            integer     150
    parallel_max_servers           
    integer
    40
    Do I have to change them ?
    I see nothing inherently wrong with them. Out of 150 processes, a maximum of 40 can be allocated to Parallel Slaves. It all depends how well you're managing/using parallel option on your workload.

  • To find out the min and max memory been used by each parameter under SGA_MA

    Hi,
    Can any please tell me how to find out the min and max memory been used by each parameter under SGA_MAX and SGA_TARGET ? below is the db CRMS65T. If any such script is there please provide me
    SQL> select name from v$database;
    NAME
    CRMS65T
    SQL> show parameter sga
    NAME                                 TYPE        VALUE
    lock_sga                             boolean     FALSE
    pre_page_sga                         boolean     FALSE
    sga_max_size                         big integer 1000M
    sga_target                           big integer 1000MThanks in advance

    Can any please tell me how to find out the min and max memory been used by each parameter under SGA_MAX and SGA_TARGET ? below is the db CRMS65T. If any such script is there please provide meI guess your question is, each memory components of SGA? if so
    SQL> select * from v$sgainfo;
    NAME                                  BYTES RES
    Fixed SGA Size                      2088504 No
    Redo Buffers                       18882560 No
    Buffer Cache Size                 616562688 Yes
    Shared Pool Size                  301989888 Yes
    Large Pool Size                     4194304 Yes
    Java Pool Size                      4194304 Yes
    Streams Pool Size                         0 Yes
    Granule Size                        4194304 No
    Maximum SGA Size                  947912704 No
    Startup overhead in Shared Pool   125829120 No
    Free SGA Memory Available                 0Also check
    SQL> select COMPONENT,CURRENT_SIZE,MIN_SIZE,MAX_SIZE,USER_SPECIFIED_SIZE from v$sga_dynamic_components;
    shared pool                                                         301989888  301989888          0           209715200
    large pool                                                            4194304    4194304          0             4194304
    java pool                                                             4194304    4194304          0             4194304
    streams pool                                                                0          0          0                   0
    DEFAULT buffer cache                                                616562688  616562688          0           603979776
    KEEP buffer cache                                                           0          0          0                   0
    RECYCLE buffer cache                                                        0          0          0                   0
    DEFAULT 2K buffer cache                                                     0          0          0                   0
    DEFAULT 4K buffer cache                                                     0          0          0                   0
    DEFAULT 8K buffer cache                                                     0          0          0                   0
    DEFAULT 16K buffer cache                                                    0          0          0                   0
    DEFAULT 32K buffer cache                                                    0          0          0                   0
    ASM Buffer Cache                                                            0          0          0           603979776
    13 rows selected.
    SQL>Edited by: CKPT on Sep 19, 2011 8:55 AM

  • Min and max functions

    Hi,
    I need to perform a calculation:
    (max(min(C,2.375),0)+max(min(Y,2.375),0))/6
    if the value of c is less than 2.375 then it has to accept the value of C else 2.375.
    on it i need to perform the max operation.
    How can i do this?

    Hi,
    MIN and MAX, like all the aggrgate functions, take only one argument.
    Perhaps you're thinking of the row functions LEAST and GREATEST, which can take one or more arguments.
    For example:
    GREATEST ( LEAST ( c
                     , 2.375
             , 0
             )will return
    2.375 if c is greater than 2.375,
    0 if c is less than 0, or
    c otherwise.
    CAUTION: Unlike the aggregate functions, that ignore NULLs, GREATEST and LEAST will return NULL if any of their arguments are NULL.

  • MIN and MAX datetimes ti find  range

    I am using Oracle 11g version
    create table re(Name char(20),Datetime char(45),val1 number);
    insert into re values('abc','10/29/2012 13:00','1.5')
    insert into re values('abc','10/29/2012 13:05','1.5')
    insert into re values('abc','10/29/2012 13:10','1.5')
    insert into re values('abc','10/29/2012 13:15','1.5')
    insert into re values('abc','10/29/2012 13:20','0.00')
    insert into re values('abc','10/29/2012 13:25','0.00')
    insert into re values('abc','10/29/2012 13:30','0.00')
    insert into re values('abc','10/29/2012 13:35','0.00')
    insert into re values('abc','10/29/2012 13:40','2.1')
    insert into re values('abc','10/29/2012 13:45','2.3')
    insert into re values('abc','10/29/2012 13:50','2.1')
    insert into re values('abc','10/29/2012 13:55','2.1')
    insert into re values('abc','10/29/2012 14:00','2.2')
    O/P:
    In this way data is stored in database.Needed output is, I want the datetime column data range with min and max values where val1>0 only.
    Expected result while we consider the above data is::
    Name mintime maxtime
    abc 10/19/2012 13:00 10/19/2012 13:15
    abc 10/29/2012 13:40 10/29/2012 14:00
    For this I tried something like this,
    select name, min(to_date(Datetime ,'mm/dd/yyyy hh24:mi')) start, max(to_date(Datetime ,'mm/dd/yyyy hh24:mi')) end from (
    select name, Datetime ,to_date(Datetime ,'mm/dd/yyyy hh24:mi') - rank() over (partition by loc_name order by t1 asc) Val_col from re where val1 > 0
    ) group by lname, Val_col
    but I am getting the output like this for above query.
    name start end
    abc 10/29/2012 13:00 10/29/2012 13:00
    abc 10/29/2012 13:05 10/29/2012 13:05
    so.on.
    Edited by: 913672 on Apr 3, 2013 3:07 AM

    913672 wrote:
    I am using Oracle 11g version
    create table re(Name char(20),Datetime char(45),val1 number);
    insert into re values('abc','10/29/2012 13:00','1.5')
    insert into re values('abc','10/29/2012 13:05','1.5')
    insert into re values('abc','10/29/2012 13:10','1.5')
    insert into re values('abc','10/29/2012 13:15','1.5')
    insert into re values('abc','10/29/2012 13:20','0.00')
    insert into re values('abc','10/29/2012 13:25','0.00')
    insert into re values('abc','10/29/2012 13:30','0.00')
    insert into re values('abc','10/29/2012 13:35','0.00')
    insert into re values('abc','10/29/2012 13:40','2.1')
    insert into re values('abc','10/29/2012 13:45','2.3')
    insert into re values('abc','10/29/2012 13:50','2.1')
    insert into re values('abc','10/29/2012 13:55','2.1')
    insert into re values('abc','10/29/2012 14:00','2.2')
    O/P:
    In this way data is stored in database.Needed output is, I want the datetime column data range with min and max values where val1>0 only.
    Expected result while we consider the above data is::
    Name mintime maxtime
    abc 10/19/2012 13:00 10/19/2012 13:15
    abc 10/29/2012 13:40 10/29/2012 14:00
    For this I tried something like this,
    select name, min(to_date(Datetime ,'mm/dd/yyyy hh24:mi')) start, max(to_date(Datetime ,'mm/dd/yyyy hh24:mi')) end from (
    select name, Datetime ,to_date(Datetime ,'mm/dd/yyyy hh24:mi') - rank() over (partition by loc_name order by t1 asc) Val_col from re where val1 > 0
    ) group by lname, Val_col
    but I am getting the output like this for above query.
    name start end
    abc 10/29/2012 13:00 10/29/2012 13:00
    abc 10/29/2012 13:05 10/29/2012 13:05
    so.on.Firstly and most importantly do NOT store dates as char columns: that's what the DATE type is for.
    Secondly, i'm not sure how you get your output from the input, particularly as your SQL contains 'partition by loc_name' which
    doesn't even exist in your example table.
    Why has the same name got two rows with those min/max times. Are you partitioning by val1?

  • Min and Max values from entire table

     Hi,
     i have requirement in which i need to find the min and max values from the entire table.
    See the sample data 
    create table test
    Sal1 int,
    Sal2 int,
    Sal3 int
    insert into test values (100,700,5700)
    insert into test values (200,3300,5300)
    insert into test values (4400,1200,3500)
    insert into test values (5400,5600,3100)
    i want the output as 100 and 5700.. how can i achieve this in a single query. Please through some light on this topic..!
    Thanking you in advance
    Regards,
    Balaji Prasad B
    Balaji - BI Developer

    Below is an example with a subquery for each of the queries Mohammad posted in order to return both min and max in a single result set.
    SELECT ( SELECT MAX(Maxx) AS Maxx
    FROM test UNPIVOT
    ( Maxx FOR E IN ( Sal1, Sal2, Sal3 ) ) AS unpvt
    ) AS Maxx
    , ( SELECT MIN(Minn) Minn
    FROM test UNPIVOT
    ( Minn FOR E IN ( Sal1, Sal2, Sal3 ) ) AS unpvt
    ) AS Minxx;
    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

  • Distinct and max more than 2 column

    Hi All,
    Need help here. I have one table and need to display latest revision. But the problem is, i cannot use DISTINCT for column TITLE and MAX also failed when column is more than 2. I'm really stuck
    I try below SQL statement but failed:
    SELECT title, MAX(revision), coordinator
    FROM specification
    GROUP BY title, coordinator
    But if my table have only 2 column, it's working:
    SELECT title, MAX(revision)
    FROM specification
    GROUP BY title
    Table Name: SPECIFICATION
    TITLE          REVISION          COORDINATOR
    SPEC-01          A                          John
    SPEC-01          B                          Michelle
    SPEC-01          C                          Andrew
    SPEC-01          D                          John
    SPEC-02          A                          Jenny
    SPEC-02          B                          Robert
    The result should be like below:
    TITLE          REVISION          COORDINATOR
    SPEC-01          D                          John
    SPEC-02          B                          Robert
    Edited by: 872733 on Jul 18, 2011 1:14 AM

    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE    11.1.0.7.0      Production
    TNS for Linux: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - Production
    SQL> with t
      2  as
      3  (
      4   select 'SPEC-01' title, 'A' revision, 'John' coordinator from dual union all
      5   select 'SPEC-01', 'B', 'Michelle' from dual union all
      6   select 'SPEC-01', 'C', 'Andrew' from dual union all
      7   select 'SPEC-01', 'D', 'John' from dual union all
      8   select 'SPEC-02', 'A', 'Jenny' from dual union all
      9   select 'SPEC-02', 'B', 'Robert' from dual
    10  )
    11  select title, max(revision) revision, max(coordinator) keep(dense_rank first order by revision
    desc) coordinator
    12  from t
    13  group by title
    14 
    SQL> /
    TITLE   R COORDINA
    SPEC-01 D John
    SPEC-02 B RobertCheck this link for more information.
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/functions058.htm#SQLRF00641
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/functions001.htm#i81407
    Regards
    Raj

  • How to show Min and Max values when another value "changes to a new value"

    Hi
    If I have this data (generated with this query: SELECT 1 A, 1 B UNION ALL SELECT 2, 1 UNION ALL SELECT 3, 2 UNION ALL SELECT 4, 2 UNION ALL SELECT 5, 1)
    A B
    1 1
    2 1
    3 2
    4 2
    5 1
    How can I generate this data (created with this query SELECT 1 Amin, 2 Amax, 1 B UNION ALL SELECT 3, 4, 2 UNION ALL SELECT 5, 5, 1)
    Amin Amax B
    1 2 1
    3 4 2
    5 5 1
    Thanks.

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. You also do not know the ANSI/ISO syntax for insertion and you did the old Sybase insertion kludge wrong, that we need keys, etc.
    CREATE TABLE Foobar
    (foo_seq INTEGER NOT NULL PRIMARY KEY,
     glop_score INTEGER NOT NULL);
    INSERT INTO Foobar
    VALUE
    (1,1),
    (2,1),
    (3,2),
    (4,2),
    (5,1);
    >> How can I generate this data (created with this query SELECT 1 Amin, 2 Amax, 1 B UNION ALL SELECT 3, 4, 2 UNION ALL SELECT 5, 5, 1) <<
    This makes no sense; you have the wrong syntax and mixed data types. My guess is: 
    SELECT MIN(foo_seg), MAX(foo_seq), MAX(glop_score)
      FROM Foobar
     GROUP BY glop_score
    HAVING MIN(glop_score) = MAX(glop_score); 
    Amin Amax B
    1 2 1
    3 4 2
    5 5 1
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Query about min and max and middle row of a table

    suppose i have table emp and field
    v_date date;
    which has data in time stamp
    time
    10:20
    10:25
    10:30
    10:32
    10:33
    10:35
    10:36
    10:38
    I need only min time and max time and two record between min and max

    I need only min time and max time and two record between min and max Like this?
    SQL> create table t (id number);
    Table created.
    SQL>
    SQL> insert into t values (1020);
    1 row created.
    SQL> insert into t values (1025);
    1 row created.
    SQL> insert into t values (1030);
    1 row created.
    SQL> insert into t values (1032);
    1 row created.
    SQL> insert into t values (1033);
    1 row created.
    SQL> insert into t values (1035);
    1 row created.
    SQL> insert into t values (1036);
    1 row created.
    SQL> insert into t values (1038);
    1 row created.
    SQL>
    SQL> commit;
    Commit complete.
    SQL>
    SQL> select * from t;
         ID
       1020
       1025
       1030
       1032
       1033
       1035
       1036
       1038
    8 rows selected.
    SQL>
    SQL>
    SQL> select decode(rownum, 1, min_val, 4, max_val, next_val) your_data from (
      2  select first_value (id) over (partition by 'a' order by 'a') min_val,
      3         last_value (id) over (partition by 'a' order by 'a')  max_val,
      4         id,
      5         lead(id) over (partition by 'a' order by id) next_val
      6   from t
      7  order by id
      8   )
      9  where min_val <> next_val and max_val <> next_val
    10  and rownum <= 4;
    YOUR_DATA
         1020
         1030
         1032
         1038
    SQL>

  • Alert Queries and Max lines displayed

    I have a query that I have set as an alert which triggers every monday morning. The query selects about 5000 rows from OITM but the alert only displays the first 90 or so. I also have SAP B1 set to email them to me but I get only the same 90 that show up in the alert window.
    Is there any way to get the full 5000? I assume there is a max rows displayed setting somewhere and I am not seeing it.
    Thanks.
    [Edit]
    I just read that the max alerts size in B1 is 64K. Is this correct? If so it might explain the problem. That being the case, how can I automatically email my self the results of the query? Should I go outside SAP and use some SQL process? (MS SQL '08)
    Edited by: Erik S. on May 24, 2010 8:17 PM

    Thanks for the reponses. I ended up doing an alert directly from SQL and cut out the middle-man.
    I have to have 5000+ rows because I then give the file to my customers who incorporate my inventory on hand into their ecomm solutions. It is the only way that I have found to give exposure to inventory levels without creating a view for them in SQL.

Maybe you are looking for

  • Mac OSX 10.4.5 folder with ? at startup

    I no longer needed OS 9.2.2 and got rid of it from my machine, I had deleted all my OS 9 applications and files (that I was aware of. I had trouble deleting the 0S 9 system folder and used Mac Cocktail to delete it. Now when I restart my machine, I g

  • K7D Master does not recognize 1GB Reg ECC modules

    I have an older K7D Master (2 CPU) which runs fine with 256 MB and/or 512 MB modules (all Kingston REG Ecc). The board also runs fine with 2 x 512 MB non ECC. But when I use Kingston 1GB modules Reg ECC (KVR266X72RC25/1024) I get an error: "AWARD Boo

  • My Applications Don't launch ..:(

    Hello Again ..!! I migrated from Snow Leopard to Mavericks on my late 2009 unibody macbook. The installation went well but now I'm having a terrible time working on my mac. Most of my applications such as (Terminal / App Store / Software Update / Cam

  • IDVD Will Not Complete Burning

    I'm not quite sure why iDVD is having this problem. I have been able to burn DVDs in the past using the app, and all of a sudden, it won't seem to complete fully what I direct it to do. Can someone help point me in the right direction? This the scree

  • Release schedule, Oracle/Sun deal etc ...

    Hi, I am a newbie to RIA and am trying to come upto speed with JavaFX. This technology choice wins over Adobe-Flash and Silverlight for me, given that my app is in Java and consequently the fact that JavaFX and Java both run on the same JVM is the mo