我正在尝试在PHP中运行此SQL查询:
$sql="select b.company as c, c.company, c.resellerid from billing b, customer c WHERE (b.company = c.customerid OR b.company = c.voip_account OR b.company = c.sequence) AND c.resellerid = '0' and source = 'CDR' group by b.company asc ";
$rs=mysql_query($sql,$conn);
while($result=mysql_fetch_array($rs)) {
$sql2="select company,extension,phone,calltype,seconds,who,customer_bill,inclusive,timestamp from billing where company='".$result["c"]."' and source='CDR' ";
$rs2=mysql_query($sql,$conn);
$result2=mysql_fetch_array($rs2);
echo $result["c"].' - '.$result2["company"].'<br>';
}
billing.company
可以与以下任何内容相同
customer.sequence
customer.customerid
customer.voip_account
我想选择billing
表中customer.resellerid = 0
和
billing.company = customer.sequence OR billing.company = customer.customerid OR billing.company = customer.voip_account
但返回的行resellerid
不等于0
答案 0 :(得分:0)
我不明白为什么有两个问题......
SELECT DISTINCT b.company b_company
, b.extension
, b.phone
, b.calltype
, b.seconds
, b.who
, b.customer_bill
, b.inclusive,timestamp
, c.company c_company
, c.resellerid
FROM billing b
JOIN customer c
ON b.company IN(c.company,c.voip_account,c.sequence)
AND c.resellerid = 0
AND source = 'CDR'
ORDER
BY b.company;
请注意,PHP的mysql_ API早已弃用