Sign Up

Sign Up to our social questions and Answers to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In


Have an account? Sign In Now

Sign In

Login to our social questions & Answers to ask questions, answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Sorry, you do not have permission to add post.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Oraask Logo Oraask Logo
Sign InSign Up

Oraask

  • Write
    • Add A New Post
    • Ask A Question

Oraask Navigation

Search
Ask A Question

Mobile menu

Close
  • Categories
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Dev Tools
    • Online Compiler
    • Base64 Converter
  • Wiki
    • SQL Tutorials
    • Java Tutorials
    • Python Tutorials
    • JavaScript Tutorials
Home/ Questions/Q 4961
Next
In Process

Oraask Latest Questions

Question
oracle user
  • 0
  • 0
oracle userExplorer
Asked: April 7, 20172017-04-07T21:39:47+03:00 2017-04-07T21:39:47+03:00In: Oracle SQL

need query to display ‘job’ & their counts & then display the no. of distinct ‘dept no’ under each ‘job’ & their counts ?

  • 0
  • 0

hello experts,

what i want is :  query to display ‘job’ & their counts & then display the no. of distinct ‘dept no’ under each ‘job’ & their counts ?

consider i have these dataset :

SQL> select * from dept;

DEPTNO DNAME LOC
———- ————– ————-
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON

SQL> select * from emp;

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
—– ———- ——— ———- ——— ———- ———- ———-
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10

thanks.

departmentsemployeesoraclequerysql
1
  • 1 1 Answer
  • 855 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    Related Questions

    • How to get Column Names from a Table in Oracle
    • What are the different types of case manipulation functions available in Oracle SQL
    • What is the use of ADD, DROP and MODIFY Commands
    • What are the differences between SQL and PL/SQL in Oracle
    • What is the use of LIMIT and OFFSET in SQL

    1 Answer

    • Voted
    • Oldest
    • Recent
    1. Beter
      Beter Explorer
      2017-04-21T18:51:04+03:00Added an answer on April 21, 2017 at 6:51 pm

      Hi,

      [code]

      SQL> select job, count(*)
      from scott.emp
      group by job
      order by 1;

      [/code]

      JOB COUNT(*)
      ANALYST 2
      CLERK 4
      MANAGER 3
      PRESIDENT 1
      SALESMAN 4
       
      5 rows selected.

      [code]

      SQL>select job, count(distinct deptno), count(*)
      from scott.emp
      group by job
      order by 1;

      [/code]

      JOB COUNT(DISTINCTDEPTNO) COUNT(*)
      ANALYST 1 2
      CLERK 3 4
      MANAGER 3 3
      PRESIDENT 1 1
      SALESMAN 1 4
           
      5 rows selected.

      [code]

      select job, deptno, count(*)
      from scott.emp
      group by job,deptno
      order by 1,2;

      [/code]

       

      JOB DEPTNO COUNT(*)
      ANALYST 20 2
      CLERK 10 1
      CLERK 20 2
      CLERK 30 1
      MANAGER 10 1
      MANAGER 20 1
      MANAGER 30 1
      PRESIDENT 10 1
      SALESMAN 30 4
       
      9 rows selected.

       

      In order to put that in a PLSQL procedure, for each SQL you can do

      set serverout on

      [code]
      begin
            for i in ( “yoursql” )
            loop
                 dbms_output.put_line( “attributes” );
             end loop;
      end;

      [/code]

      hope this help.

        • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp

    Leave an answer
    Cancel reply

    You must login to add an answer.

    Forgot Password?

    Need An Account, Sign Up Here

    Sidebar

    Adv 250x250

    Explore

    • Categories
    • Questions
      • New Questions
      • Trending Questions
      • Must read Questions
      • Hot Questions
    • Dev Tools
      • Online Compiler
      • Base64 Converter
    • Wiki
      • SQL Tutorials
      • Java Tutorials
      • Python Tutorials
      • JavaScript Tutorials

    Footer

    Oraask

    About

    Oraask is a website for developers and software engineers who want to learn new skills, share their knowledge, and solve their coding problems. Oraask provides free content on various programming languages and topics, such as Oracle, Python, Java, etc. Oraask also allows users to ask questions and get answers from other members of the community.

    About Us

    • About Us
    • Contact Us

    Legal Stuff

    • Privacy Policy
    • Terms & Conditions

    Follow

    Oraask is licensed under CC BY-NC-SA 4.0Oraask CopyrightOraask CopyrightOraask CopyrightOraask Copyright

    © 2019 Oraask. All Rights Reserved
    With Love by Oraask.

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.