From Database
ID Name Department position
================================
1 A MK IT
2 B MK RD
3 C MK EN
4 D BD IT
5 E BD RD
6 F BD EN
7 G BD IT
8 H OB IT
9 I MK EN
how to write the code to display in table as following this
display something like this in the table
position/departmet MK BD OB
===================================
IT 1 2 1
RD 1 1 0
EN 2 1 0
i just confuse.
Try it by using
CASE,SQLFiddle Demo
Or use
Prepared Statementif you have unknown number of columnsSQLfiddle Demo