| |

VerySource

 Forgot password?
 Register
Search
View: 581|Reply: 5

Can you implement a SQL statement to count how many teachers there are in each department? For example, you can generate

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-21 14:30:01
| Show all posts |Read mode
Find a SQL statement:

Table A: eis_dict_depart records the teacher department name

i_code c_name
  1 Principal's Office
  2 Teaching Office
 ........


Table B: eis_tech_info records all teacher information (id: automatic number; techname: teacher name; departid: department number)

id techname departid
1 sheet three 1
2 Reese 2
3 King 2 2
4 Mazi 2
........


Can you implement a SQL statement to count how many teachers there are in each department? For example, you can generate the following table

c_name total
Principal's office 1
Teaching Office 3
Reply

Use magic Report

0

Threads

7

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-5-4 07:00:02
| Show all posts
select c_name, count (*) from (select t.techname, t.departid, d.c_name
 from tech_info t left join in depart d on t.departid = d.departid) a group by t.t.departid, t.c_name
Reply

Use magic Report

1

Threads

11

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-5-4 12:45:01
| Show all posts
SELECT COUNT (*) AS techCount, c_Name
FROM eis_tech_info INNER JOIN eis_dict_depart ON
       eis_tech_info.departid = eis_dict_depart.i_code
GROUP BY eis_tech_info.departid
Reply

Use magic Report

1

Threads

11

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-5-4 13:00:01
| Show all posts
It is recommended to look at the online help of SQL Server, these are too simple.
Reply

Use magic Report

0

Threads

7

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-5-4 15:45:01
| Show all posts
select c_name, count (*) from (select t.techname, t.departid, d.c_name
 from dbo.eis_tech_info t left join dbo.eis_dict_depart d on t.departid = d.i_code) a group by departid, c_name
Reply

Use magic Report

0

Threads

7

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-5-4 16:30:01
| Show all posts
The code has been tested. You can use it directly
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list