<?php
$connection = mysql_connect("localhost","root","1234") or die("เชื่อมต่อฐานข้อมูลไม่ได้");
$db = mysql_select_db("workpermit" , $connection ) or die ("ติดต่อฐานไม่ได้");
mysql_query("SET NAMES UTF8");
$sql = "SELECT SUM (CASE WHEN permit_sex = 'ชาย' THEN 1 ELSE 0 END ) AS MALE,
SUM( CASE WHEN permit_sex = 'หญิง'THEN 1 ELSE 0 END ) AS FEMALE
FROM workpermit
WHERE d_receive
BETWEEN '2552-08-25'AND '2552-09-19' ";
$sql_result = mysql_query($sql,$connection) or die ("เอ็กซิคิวต์คำสั่งไม่ได้ ");
$rsCount_2 = mysql_result($sql_result,0);
echo ?จะแสดงผลอย่างไรครับ?
?>
select (select count(*) from workpermit where permit_sex='ชาย' where d_receive between '2552-08-25' and '2552-09-19') SUM_MALE,
(select count(*) from workpermit where permit_sex='หญิง' where d_receive between '2552-08-25' and '2552-09-19') SUM_FeMALE
from workpermit
SELECT
CASE WHEN permit_sex = 'ชาย' THEN +1 END AS MALE,
CASE WHEN permit_sex = 'หญิง' THEN +1 END AS FEMALE
FROM workpermit
WHERE d_receive BETWEEN '2552-08-25' AND '2552-09-19'