Can you explain this query SQL - view included Inline

The query is taken from "Oracle Database 10g: SQL Fundamentals II" page 3-7 (Chapter 3)

I do not understand completely the following query:

SELECT a.last_name, a.salary, a.department_id, b.salavg
EMPLOYEE a, (SELECT department_id,
AVG (salary) salavg
Employees
GROUP BY department_id) b
WHERE a.department_id = b.department_id
AND a.salary > b.salavg;


The sight of inline can return multiple records. Can you please tell me step by step how does this work. I understand the concept of join tables and alias, etc. I just need to know the mechanism of the present code.


Thank you

Inlive view returns the average wage against each of the Department avaiable IDs. And the query returns the names of the employees in each Department having wage greater than the average salary of all employees belonging to the same Department, as it is.

Tell Mr. Abbott and Mr. Babbitt belong to the same SALES Department and say that they are the only two in that Department.
Assume the salary of Mr. Abbott's $ 500 and the salary of Mr. Babbitt is $ 400, the average salaries in the COMMERCIAL service would be 450.

When the query is run in this case,
DepartmentID of Mr. Abbott, name, salary would be returned as well as the average in that Department, because his salary is 500 $ > $450 (on average).

HTH,
Aswin.

Published by: ice_cold_aswin on July 26, 2009 19:24

Tags: Database

Similar Questions

  • My computer is clearly marked with the Windows 7 Logo, but works under XP, can you explain this? IM lost

    I have a HP Probook 6545 B, which has the Windows 7 logo plastered everywhere. However, when starting, shows that it is indeed NOT running Windows 7 instead, running on Windows XP. Why is this? Is it possible that it can be 'cancelled' or restored to this OS somehow? Windows 7 is stored in a hidden file of OS on my hard drive of the computer somewhere? If so, how caould I find and restore dump XP and 7?

    You bought the new laptop or used? Most of the business line of laptops come with Windows 7 had the possibility to order with the downgrade to XP, if you wish.

    Click here >Contact HP to order Windows 7 recovery discs to change the OS.

  • Once I downloaded the new version of firefox, it flashes that it cannot complete because I have no privileges to certain things in the new version. Can you explain this?

    I get throughout the download process and move it in my applications. He then asks me if I want to replace the old version with the new. When I click on replace, a new window appears with the fact that my computer does not have privileges for the operations so I can not complete the process. Well, that really gets me, is that it appears always say that I need to download the new version. I don't know what to do.

    If he has problems with the update or the permissions then simpler is to download the full version and trash the version currently installed to do a clean install of the new version.

    Download a new copy of the Firefox program and save the file on the desktop disk image (dmg)

    • Trash the present application Firefox to do a clean (re-) install
    • Install the new version you downloaded

    Your profile data is stored in the Firefox profile folder, so you will not lose your bookmarks and other personal data if you uninstall and (re) install Firefox.

  • Can you explain this timestamp syntax?

    http://psoug.org/reference/timestamp.html shows the following syntax:

    INSERT INTO ts_test (x, y, z)
    VALUES (timestamp'2007 - 08 - 08 09:00:00.123456789',)
    Timestamp'2007 - 08 - 08 09:00:00.123456789',.
    Timestamp'2007 - 08 - 08 09:00:00.123456789');

    I checked that it works. But what is the syntax timestamp «...» » ? Which throws the value of a data type timestamp or something?

    Can I use single quotes to cast to other types? This syntax does not work: select char '111' double;

    It is a literal stamp, please visit: http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/sql_elements003.htm#BABGIGCJ

  • Can you explain why the "analytical" Word is used in Sql

    I found to define the "analytic function" phrase is such: "a piece of syntax that is originating excessive."
    I don't understand why's called it "Analytics". In English 'analytical' comes from the word "to analyse" which means the examination of something. So it looks like "analytic function" should review/analyze something? but all the functions examaine/analyze something. If I group by article in my request, then all aggregate functions will conduct the review of the data, then why I call them better too 'analytic (al). Can you explain why the "analytical" Word is used in Sql world?

    CharlesRoos wrote:
    I found to define the "analytic function" phrase is such: "a piece of syntax that is originating excessive."
    I don't understand why's called it "Analytics". In English 'analytical' comes from the word "to analyse" which means the examination of something. So it looks like "analytic function" should review/analyze something? but all the functions examaine/analyze something. If I group by article in my request, then all aggregate functions will conduct the review of the data, then why I call them better too 'analytic (al). Can you explain why the "analytical" Word is used in Sql world?

    Aggregate functions will bring together data that is to sum or count etc once it is grouped together. It is not just review, but grouping.
    Analytical functions review / analyze the other rows of data, without having to group them in the result that they can summarize a set of values of a particular group (partition) of the data, or they can simply retrieve values of other lines (for example lead, lag, the first_value, last_value etc. functions.) They are able to look through the data without any aggregation of it. So why they are analytical.

  • I continue to receive reports of Norton that a download with the pre RadioWMPCoreGecko fix. followed by various suffixes like "19.dll" or 05, 06 08 etc... takes a lot of computer resources. Can you explain what it is, as I understand it, it is called by F

    I continue to receive Norton Security reports that a download with the pre RadioWMPCoreGecko fix. followed by various suffixes like dll '19.dll' or 05.Marco, 06 08 etc... takes a lot of computer resources. Can you explain what it is, as I understand it, it is called by Firefox.

    This DLL can be part of a Firefox extension.

    Start Firefox in Firefox to solve the issues in Safe Mode to check if one of the extensions or if hardware acceleration is the cause of the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > appearance/themes).

  • can you explain the purpose of layout and describe when it should be used? __

    can you explain the purpose of layout and describe when it should be used?

    http://www.Google.com
    Use a more specific search term. This will help you get a good answer for your homework. ;-) MS - MVP - Elephant Boy computers - don't panic!

  • Can anyone simplify this query

    Here's a DOF from two tables

    1. CREATE TABLE (EMPL)
    NUMBER OF SNO
    ENAME VARCHAR2 (25).
    USE VARCHAR2 (25).
    KEY ELEMENTARY SCHOOL (SNO)
    );

    2. CREATE TABLE EMPL_DET)
    NUMBER OF SNO
    SAL VARCHAR2 (25)
    );


    Here are tables LMD
    INSERT INTO EMPL (SNO, ENAME, JOB) VALUES (1, 'SMITH', 'CLERK');
    INSERT INTO EMPL (SNO, ENAME, JOB) VALUES (2, 'SMITH', 'MANAGER');
    INSERT INTO EMPL (SNO, ENAME, JOB) VALUES (3, 'TOM', 'CLK');

    INSERT INTO EMPL_DET (SNO, SAL) VALUES (1, '1000');
    INSERT INTO EMPL_DET (SNO, SAL) VALUES (2, "10000");
    INSERT INTO EMPL_DET (SNO, SAL) VALUES (3, '900');


    I want to calculate TotalSAL (column: empl_det.) SAL) of each employee (empl.ename) with job-description (empl.job).

    Means I want following the lines of output
    1.(Job,TotalSAL,Ename)-> (CLERK, 11000, SMITH)
    2->.(Job,TotalSAL,Ename) (MANAGER, 11000, SMITH)
    3->.(Job,TotalSAL,Ename) (CLK, 900, TOM)

    I tried to write down to unique ename

    Select JOB, x.sal, ename in empl,
    (
    Select sum (sal) sal empl_det where sno in
    (select sno to empl where ename = 'SMITH')
    ) x
    where ename = 'SMITH '.
    order by ename

    each ename, I draw from this query. How can I make the ename list (TOM SMITH) to this request?
    Or can anyone simplify this query?

    Hello

    in this case, you need to use is analytical functions:

    that is to say:

      SELECT e.job, SUM (d.sal) OVER (PARTITION BY e.ename) AS "TotalSal"
           , e.ename
        FROM empl e, empl_det d
       WHERE d.sno = e.sno AND e.ename IN ('SMITH', 'TOM')
    ORDER BY e.ename;
    
    JOB                         TotalSal ENAME
    ------------------------- ---------- -------------------------
    CLERK                          11000 SMITH
    MANAGER                        11000 SMITH
    CLK                              900 TOM                      
    

    Kind regards.
    Al

    Published by: Alberto Faenza on 27 November 2012 15:34
    Corrected query

  • can someone explain this code

    Hello, when I look at this code, I do not understand a code, can someone explain this code?
    Thank you very much!!!

    The creation of a 'method' for a vector object (in the old style of class definition), which gives it a method with an argument in degrees rotate.

    It replaces the vector existing x and properties of y (in the part "with (this)" code) based on the angle that was passed.

    I don't know if it gives correct results, because I don't check the math/trig, but it is the interpretation of what I see. What exactly do you want explained more in detail?

  • I recently downloaded my favorite CD music in my I tunes library, how can you transfer this music on a USB Flash drive so that I can play the music through my stereo system H D - Bike. I'm 10 Windows on my PC

    I recently downloaded my favorite CD music in my I tunes library, how can you transfer this music on a USB Flash drive so that I can play the music through my H D - bike

    stereo system.

    I'm 10 Windows on my PC

    Select the songs in iTunes, let them slip into a file Explorer window showing the flash drive, drop.

    TT2

  • Due to a corrupted windows profile, I had to reinstall ACROBAT PRO XI.  After re - install, I kep "error 16"!  How can you fix this?

    Due to a corrupted windows profile, I had to reinstall ACROBAT PRO XI.  After re - install, I kep "error 16"!  How can you fix this?

    Hello

    Please try the link below

    In Adobe Creative Suite or Adobe Creative Cloud configuration error

    For more details, please visit https://forums.adobe.com/thread/1177032

    You can also consult Re: persistent Configuration 16 error

    Let us know if this helps!

  • Can you explain a huge difference between a manual and a model of swatch?

    I have two main question.

    one is a difference between a pettern manual (object repeatedly copy / paste) and a patron of swatch.

    and another is the reason why a swatch model is much smaller file size, then the other.

    Here are the details.

    at work,.

    someone created the white background and almost 120 lions in the box.

    Literally, copy and past the repeadily of the object to fill the box.

    He was 72mbs and eps format.

    So I created a model in swatch (ofcourse correctly) and a draw one big box and filled with model.

    and it was only under 2 mbs Al format.

    and I'm importing says my Al file to indesign and my senior designer

    I was wasting my time for nothing.

    She says even if it is less than 2 MB still all anchor points are there and takes a long time to load the file.

    and the last time that the eps file created error. But then I don't quite understand mine was boss of swatch in artificial intelligence.

    What she suggests is, create a tif with eps file file, so it's not creat any error.

    Can someone explain this?

    The difference is just like instances of symbols.

    If the objects are copied and placed manually each anchor, path and the shape is followed by the file. Each of them.

    If a ground shade is made, the original art is referenced once then called as often as necessary. Each anchor, path and the form are not stored. A set of anchors, paths and Forms data is stored, then the app simply titles where the copies.

    Using samples of model (and symbols) will increase performance in redraw and output, not to mention publishing and the size of the file (if it is a review).

  • Using Outlook Express 5, I need access to blocked senders list to locate and remove a valid sender. Can you explain the following steps to access this list.

    Outlook express 5 e-mail program Windows 98

    Hi Micasa,

    Please use the forum for answers,

    Windows 98 is not supported in this forum.  However, I can give you some suggestions that might fix your problem.  For better support, I recommend posting in Outlook Express newsgroup to get the answer you are looking for.

    MS Outlook Express Newsgroup

    I actually found the answer for you in this discussion forum.  I hope that's what you're looking for:

    Tooks | Message rules | List of blocked senders. Find the address and remove
    it.
    or
    Tools | The junk e-mail options. Blocked senders
    Select the entry, and then click on remove.

    Let us know if this helps, Kevin
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • How can I change this query to generate a sequence

    This query
     
     select 
     SZSTCLA_PIDM, 
      SZSTCLA_TERM_CODE,
      SZSTCLA_LAST_NAME
      from SZSTCLA,SHRTGPA
     where SZSTCLA_PIDM IN ( 120125,186114)
     AND SHRTGPA_TERM_CODE = SZSTCLA_TERM_CODE
     AND  shrtgpa_pidm  = SZSTCLA_PIDM 
      AND SZSTCLA_RECORDED_EARNED_CRED > 0 
      ORDER BY SZSTCLA_TERM_CODE
    Returns the following results
    SZSTCLA_PIDM     SZSTCLA_TERM_CODE      SZSTCLA_LAST_NAME
    186114     198810     Johnson
    186114     198820     Johnson
    186114     198910     Johnson
    186114     198920     Johnson
    186114     199010     Johnson
    186114     199020     Johnson
    186114     199110     Johnson
    186114     199120     Johnson
    120125     200720     Smith
    120125     200810     Smith
    120125     200820     Smith
    120125     200910     Smith
    120125     200920     Smith
    120125     201010     Smith
    120125     201020     Smith
    120125     201110     Smith
    120125     201120     Smith
    Notice that ruptures in every szstcla_pidm, I need to change the query, so it can display a sequence number for each SZSTCLA_TERM_CODE
    so, it will be like
    SZSTCLA_PIDM     SZSTCLA_TERM_CODE      SZSTCLA_LAST_NAME                                    seq 
    186114                     198810                                     Johnson                         1
    186114                     198820                                     Johnson                         2
    186114                    198910                                     Johnson                         3
    186114                    198920                                     Johnson                         4
    186114                    199010                                     Johnson                         5
    186114                    199020                                     Johnson                         6
    186114                    199110                                     Johnson                         7
    186114                    199120                                     Johnson                         8 
    then
    SZSTCLA_PIDM     SZSTCLA_TERM_CODE      SZSTCLA_LAST_NAME                                      seq 
    
    120125                  200720                                   Smith                             1
    120125                  200810                                    Smith                             2
    120125                  200820                                   Smith                              3
    120125                  200910                                   Smith                              4
    120125                  200920                                   Smith                              5
    120125                  201010                                   Smith                              6
    120125                  201020                                   Smith                              7
    120125                  201110                                   Smith                              8
    120125                  201120                                   Smith                              9

    Looks like below, this is what you are looking for, but I can't understand why some documents are missing from the sample output

        COL1 COL2     SZSTCLT_LAST_NAME              RN
    -------- -------- ------------------------------ --
    
      120125 200920   Smith                           1
      120125 201010   Smith                           2 
    

    Maybe, if you could explain it, the query can be modified to exclude these folders as well. But, for now, downwards should suffice.

    select szstclt_pidm col1, szstclt_term_code col2, szstclt_last_name, row_number() over (partition by szstclt_pidm order by szstclt_term_code) rn
      from szstclt a
           join shrtgpt b on a.SZSTCLT_PIDM = b.SHRTGPT_PIDM and a.SZSTCLT_TERM_CODE = b.SHRTGPT_TERM_CODE
     where SZSTCLT_PIDM IN ( 120125,186114);
    
        COL1 COL2     SZSTCLT_LAST_NAME              RN
    -------- -------- ------------------------------ --
      120125 200920   Smith                           1
      120125 201010   Smith                           2
      120125 201020   Smith                           3
      120125 201110   Smith                           4
      120125 201120   Smith                           5
      186114 198810   Johnson                         1
      186114 198820   Johnson                         2
      186114 198910   Johnson                         3
      186114 198920   Johnson                         4
      186114 199010   Johnson                         5
      186114 199020   Johnson                         6
      186114 199110   Johnson                         7
      186114 199120   Johnson                         8 
    
     13 rows selected 
    
  • How to optimize the performance of this query SQL

    Hello

    I need to find the age for each day, but I need for all previous dates in a single query. So I used the following query:

    Select trunc (sysdate) - level + 1 DATE

    trunc (sysdate) - level + 1 - created_date AGE

    elements

    connect by trunc (sysdate) - level + 1 - created_date > 0

    I get output (FOR the DATE and AGE) that is fine and correct:

    DATE AGE           

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

    6 JULY 15 22

    5 JULY 15 21

    4 JULY 15 20

    3 JULY 15 19

    2 JULY 15 18

    JULY 1, 15 17

    JUNE 30, 15 16

    JUNE 29, 15 15

    JUNE 28, 15 14

    JUNE 27, 15 13

    JUNE 26, 15 12

    25 JUNE 15 11

    24 JUNE 15 10

    Now I need to calculate the average age for each day and I added the average in the following query:

    Select trunc (sysdate) - level + 1 DATE .

    AVG (trunc (sysdate) - level + 1 - created_date) AVERAGE_AGE

    elements

    connect by trunc (sysdate) - level + 1 - created_date > 0

    Group of trunc (sysdate) - level + 1


    This query is correct? When I add the aggregate (avg) function to this query, it takes 1 hour to retrieve the data. When I remove the average request function that gives the result in 2 seconds? What is the solution to calculate the average without affecting performance? Help, please

    Maybe you are looking for something like this...

    SQL > ed
    A written file afiedt.buf

    1 with t (point, created_date) :)
    2 Select 1, date '' 2015-06-24 from all the double union
    3 select 2, date ' 2015-06-29 the Union double all the
    4 Select 3, date ' 2015-06-17' of the double
    5        )
    6  --
    7. end of test data
    8  --
    9. Select item
    10, trunc (sysdate) - level + 1 as dt
    11, trunc (sysdate) - level + 1-created_date age
    12, round (avg (trunc (sysdate) - level + 1 - created_date) on (trunc (sysdate) partition - level + 1), 2) as avg_in_day
    13 t
    14 connect by level<=>
    15-point point = prior
    sys_guid() 16 and prior is not null
    17 * order by 1.2
    SQL > /.
    POINT DT AGE AVG_IN_DAY
    ---------- ----------- ---------- ----------
    1 JUNE 24, 2015 0 3.5
    1 25 JUNE 2015 1 4.5
    1 26 JUNE 2015 2 5.5
    1 27 JUNE 2015 3 6.5
    1 28 JUNE 2015 4 7.5
    1 29 JUNE 2015 5 5.67


    1 30 JUNE 2015 6 6.67
    1 1 JULY 2015 7 7.67
    1-2 JULY 2015 8 8.67
    1-3 JULY 2015 9 9.67
    1 TO 4 JULY 2015 10 10.67
    1 5 JULY 2015 11 11.67
    1 6 JULY 2015 12 12.67
    2 JUNE 29, 2015 5.67 0
    2 30 JUNE 2015 1 6.67
    2 1 JULY 2015 2 7,67
    2 2 JULY 2015 3 8.67
    2-3 JULY 2015 4 9.67
    2-4 JULY 2015 5 10.67
    2-5 JULY 2015 6 11.67
    2-6 JULY 2015 7 12.67
    3 JUNE 17, 2015 0 0
    3 18 JUNE 2015 1 1
    3 19 JUNE 2015 2 2
    3 20 JUNE 2015 3 3
    3 21 JUNE 2015 4 4
    3 22 JUNE 2015 5 5
    3 23 JUNE 2015 6 6
    3 24 JUNE 2015 7 3.5
    3 25 JUNE 2015 8 4.5
    3 26 JUNE 2015 9 5.5
    3 27 JUNE 2015 10 6.5
    3 28 JUNE 2015 11 7.5
    3 29 JUNE 2015 12 5.67
    3 30 JUNE 2015 13 6.67
    3 1 JULY 2015 14 7.67
    3 2 JULY 2015 15 8.67
    3 3 JULY 2015 16 9.67
    3-4 JULY 2015 17 10.67
    3-5 JULY 2015 18 11.67
    3 6 JULY 2015 19 12.67

    41 selected lines.

Maybe you are looking for