Sign Up

Sign Up to our social questions and Answers Engine 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 Engine 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

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8974843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:45:15+00:00 2026-06-15T18:45:15+00:00

So using the following 2 tables Employee: mysql> select * from employee; +———-+——-+———+———–+————+————————–+——+——–+———–+—–+ |

  • 0

So using the following 2 tables
Employee:

mysql> select * from employee;
+----------+-------+---------+-----------+------------+--------------------------+------+--------+-----------+-----+
| Fname    | Minit | Lname   | SSN       | Bdate      | Address                  | Sex  | Salary | Superssn  | Dno |
+----------+-------+---------+-----------+------------+--------------------------+------+--------+-----------+-----+
| John     | B     | Smith   | 123456789 | 1955-01-09 | 731 Fondren, Cary, NC    | M    |  31500 | 333445555 |   5 |
| Franklin | T     | Wong    | 333445555 | 1945-12-08 | 638 Voss, Cary, NC       | M    |  42000 | 888665555 |   5 |
| Joyce    | A     | English | 453453453 | 1962-07-31 | 5631 Rice, Raleigh, NC   | F    |  26250 | 333445555 |   5 |
| Rameish  | K     | Naraya  | 666884444 | 1952-09-15 | 975 Fire Oak, Angier, NC | M    |  39900 | 333445555 |   5 |
| James    | E     | Borg    | 888665555 | 1927-11-10 | 450 Stone, Cary, NC      | M    |  55000 | NULL      |   1 |
| Jennifer | S     | Wallace | 987654321 | 1931-06-20 | 291 Berry, Garner, NC    | F    |  43000 | 888665555 |   4 |
| Ahmad    | V     | Jabbar  | 987987987 | 1959-03-29 | 980 Dallas, Cary, NC     | M    |  25000 | 987654321 |   4 |
| Alicia   | J     | Zelaya  | 999887777 | 1958-07-19 | 3321 Castle, Apex, NC    | F    |  25000 | 987654321 |   4 |
+----------+-------+---------+-----------+------------+--------------------------+------+--------+-----------+-----+
8 rows in set (0.01 sec)

Department:

mysql> select * from department
    -> ;
+---------+----------------+-----------+
| dnumber | dname          | mgrssn    |
+---------+----------------+-----------+
|       1 | Headquarters   | 888665555 |
|       2 | Development    | NULL      |
|       3 | Sales          | NULL      |
|       4 | Administration | 987654321 |
|       5 | Research       | 333445555 |
+---------+----------------+-----------+
5 rows in set (0.00 sec)

I need to combine information using the having clause which department’s employees have an average salary greater than 33000.
This is a copy of the output:

+--------------+-------------+
| dname        | AVG(salary) |
+--------------+-------------+
| Headquarters |       55000 |
| Research     |       35000 |
+--------------+-------------+

Ok where I am so far:

mysql> select d.dname, AVG(salary)
    -> from department as d, employee as e
    -> having avg(salary) > 33000
    -> group by d.dname;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to
use near 'group by d.dname' at line 4
mysql> select d.dname, AVG(salary)
    -> from department as d, employee as e
    -> having avg(salary) > 33000
    -> group by ????

What am I missing for the group by?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:45:16+00:00Added an answer on June 15, 2026 at 6:45 pm

    This and all your other questions smell like you’re doing some test or course. Shouldn’t it be time that you at least attempt to solve one of these questions yourself?

    select
      d.dname,
      AVG(salary)
    from
      department d
      inner join employee e on e.Dno = d.dnumber
    group by
      d.dname
    having
      avg(salary) > 33000
    

    First of all, I use d and e as aliases for Department and Employee. You can specify aliases after the table name in the query. You can use them to prefix field names, but you don’t have to if that field exists in only one table.

    Let’s continue with the inner join. There’s a relation between the tables. It looks like department.dnumber contains the department number. Also, employee.Dno contains the department number of the employees. By joining the table, you combine the data. The query will return a row for each department and for all employees. The information of the department is duplicated for each employee that is returned.

    The the aggregation. SQL knows a number of aggregate functions. If you select a field or a couple of fields to ‘group’ by, you can use other fields to ‘aggregate’ over. So in this case, I group by department name. I earlier said it would the return the department information multiple times, one time for each employee of the department. Now, this step groups that information again. It returns the department name only one time, and aggregates the employee information. In this case, I use AVG to calculate the avarage salary, but you could also use SUM(salary) to get the total salary of all employees in the department, or COUNT(*) to count the number of employees per department.

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

Sidebar

Related Questions

I am using the following InnoDB tables in mysql to describe records that can
I am using VB.NET with LINQ to MS SQL. I have two following tables.
I am using CakePHP 2.0's integrated Auth component. I have the following tables :
I have following view <asp:Content ID=Content2 ContentPlaceHolderID=MainContent runat=server> <h2>Tables <%=ViewData[RetriverName] %></h2> <%using (Html.BeginForm(ResfreshSelectedTables, Home))
Consider the following scenario: Tables: Employee (EmpId(PK), Name) TeamMembers(TeamId(PK), EmpId(PK)) Project(ProjId(PK), TeamId) I really
I have the following tables: employee(ename,street,city) where ename is primary key company(cname, city) where
I am using the following code to fetch data from a database table: <!DOCTYPE
Got a relatively simple MySQL query that I'm pulling using php with the following
I have two tables in my database as following: Employee Table: Username, Name, Job,
I'm trying to create a the following table using MySQL: CREATE TABLE registrations (

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

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.