有什么方法可以组合以下查询(我们可以使用COUNT或其他方法组合这些查询)。

$resultacgc = mysql_query("SELECT mno FROM table1 WHERE (m_jid='$sid' AND decision='accept-gf')");
  $numacgc = mysql_num_rows($resultacgc);
$resultacp = mysql_query("SELECT mno FROM table1 WHERE (m_jid='$sid' AND decision='accept-p')");
  $numacp = mysql_num_rows($resultacp);
$resultacpc = mysql_query("SELECT mno FROM table1 WHERE (m_jid='$sid' AND decision='accept-pc')");
  $numacpc = mysql_num_rows($resultacpc);
$resultacr = mysql_query("SELECT mno FROM table1 WHERE (m_jid='$sid' AND decision='accept-rdy')");
  $numacr = mysql_num_rows($resultacr);
$resultacft = mysql_query("SELECT mno FROM table1 WHERE (m_jid='$sid' AND decision='accept-ft')");
  $numacft = mysql_num_rows($resultacft);


附注:我知道“ mysql_ *”已弃用。

谢谢

最佳答案

您可以使用mysql IN。

像这样:

"SELECT mno FROM table1 WHERE (m_jid='$sid' AND decision IN ('accept-gf', '...', '...'))"


如果要获取每个计数,则需要执行以下操作:

"SELECT decision, COUNT(*) AS count FROM table1 WHERE (m_jid='$sid' AND decision IN ('accept-gf', '...', '...')) GROUP BY decision"

09-11 03:05