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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
The Five Tenets of the Most Secure Backup

Data loss can hit a business in any number of ways. In reality, companies should expect to lose data at some point. The challenge is having a plan to recover from such an event.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.