有没有办法合并以下查询(我们可以使用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);
P.S。:我知道“mysql_ *”已被弃用。
谢谢
答案 0 :(得分:0)
您可以使用mysql IN。
像这样:
string = "/challenges/:challenge_id/submissions/:id"
# To get a matching params array
string.scan(/:\w+/) # => [":challenge_id", ":id"]
# To replace them with "1"s
string.gsub(/:\w+/, '1') # => "/challenges/1/submissions/1"
如果你想得到每个计数,你需要做这样的事情:
"SELECT mno FROM table1 WHERE (m_jid='$sid' AND decision IN ('accept-gf', '...', '...'))"