what will be mysql query to display result as i required ?? ( counting records and display count for each category)

There are four Categories of employee
DRDS
DRTC
Admin
Allied

Each Category has certain Posts

there are three tables
Category master (category will be selected from here) [CategoryId]
designationmaster [DesignationId] [Category]
employee master [Designation]

CategoryId = Category
 DesignationId = Designation

i want to display data as per category selected from dropdown menu
for example i have selected DRDS
Under DRDS following are post like  Sc. B   Sc. C     Sc .D  Sc .E  etc

i want to display number of emloyees in every post of selected category


For example if I select DRDS Output should be like this
  HELD is number of employees of that post

RANK         HELD
Sc. H           01
Sc. G           07
Sc. F           05
Sc. E           02
Sc .D          10
Sc. C          15
Sc .B          07

similarly if i select DRTC  Output should be like this

RANK         HELD
TO D           03
TO C           33
TO B           35
TO A           29

Screenshots of tables are attached.


what will be the mysql query for this ??
how to fetch data from this query and display its count for every post of certain category
v sResearcherAsked:
Who is Participating?
 
Julian HansenConnect With a Mentor Commented:
SELECT
  count(*) as HELD, 
  designation
FROM
  posts
WHERE
  category = 'DRDS'
GROUP BY
  designation

Open in new window

That is the basic structure - you might need to add in some Joins to get the actual categories / and deisgnation's instead of their id's but what you are doing here is selecting the total designations by category.
0
 
v sResearcherAuthor Commented:
@Julian Hansen
 whats wrong with this query.. its not working

"SELECT COUNT(*) AS held , d.DesignationDescription from employeemaster e LEFT JOIN  designationmaster d ON
                 d.DesignationId= e.Designation WHERE d.Category = ".$Category."GROUP BY e.Designation";
0
 
Julian HansenCommented:
Not working is a very broad term
- It gives an error: In which case which error
- It does not return the right results: What results does it return
0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
v sResearcherAuthor Commented:
no error
 but not returning anything
0
 
v sResearcherAuthor Commented:
Ok sir ... Its done by replacing Designation by DesignationDescription

thank you for your help :)
0
 
Julian HansenCommented:
You are welcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.