Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: SQL*PLUS question

Re: SQL*PLUS question

From: Tim Shute <Tshute_at_nospamnisoft.co.uk>
Date: Wed, 17 Mar 1999 09:01:27 +0000
Message-ID: <SQdMbCAn9272IATA@nisoft.demon.co.uk>


In article <7cn8kb$onk$2_at_news.udel.edu>, Hemei <Hemei_at_yahoo.com> writes
>I have one table, table_a which has two attributes group_id and rate. What I
>want is to retrieve the medium value for each group_id. For example,
> table_a:
> group_id rate
> ------------ ------
> 01 1.0
> 01 1.1
> 01 1.2
> 02 2.1
> 03 3.1
> 03 3.4
> 03 4.0
> 03 4.1
> 03 5.0
>what I want is something like:
> group_id rate
> ------------ ------
> 01 1.1
> 02 2.1
> 03 4.0
>Is there a easy way to do this with sql*plus? Thanks.
>
>Peng Nie
>
>

This is close - I wasn't sure what you meant by the 'medium' so I used the average.

SQL> select * from sqltest;

FIELD1 FIELD2
---------- ---------

01               1.1
01                 1
01               1.2
02               2.1
03               3.1
03               3.4
03                 4
03               4.1
03                 5

9 rows selected.

SQL> select field1, avg(field2)
  2 from sqltest
  3 group by field1;

FIELD1 AVG(FIELD2)
---------- -----------

01                 1.1
02                 2.1
03                3.92

HTH
--
Tim Shute
Software Engineering Manager

NiSoft (UK) Limited
Internet: www.nisoft.co.uk Received on Wed Mar 17 1999 - 03:01:27 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US