如何顯示1多個列旁邊U2叫學生總數累計總
它應該顯示總人數總支付報酬,並根據輔導員總所致。
考慮我有C1,C2,C3,C4作爲輔導員和U1,U2作爲大學 說C1有5個學生,在這種情況下,累計總數列各大學應該向學生展示列的總數[C1] [沒有學生]的= 10,[C1] [應付帳款] =一定的價值,[C1] [付費] =一定的價值,[C1] [Balence] =一些價值
請檢查下面的代碼,讓我知道是否有任何方法來編寫選擇查詢內部SUM聚合函數或任何備用解決方案,因爲我想wll_invoice.total_payable應gr oup by customer_id。
<?php
define('DB_MAIN', 'localhost|user|passowd|database');
class my_db{
private static $databases;
private $connection;
public function __construct($connDetails){
if(!is_object(self::$databases[$connDetails])){
list($host, $user, $pass, $dbname) = explode('|', $connDetails);
$dsn = "mysql:host=$host;dbname=$dbname";
self::$databases[$connDetails] = new PDO($dsn, $user, $pass);
}
$this->connection = self::$databases[$connDetails];
}
public function fetchAll($sql){
$args = func_get_args();
array_shift($args);
$statement = $this->connection->prepare($sql);
$statement->execute($args);
return $statement->fetchAll(PDO::FETCH_OBJ);
}
}
$db = new my_db(DB_MAIN);
$universities = $db->fetchAll('SELECT distinct customer_university FROM wll_customer');
$counselors = $db->fetchAll('SELECT distinct customer_counselor FROM wll_customer');
$payments_ = $db->fetchAll('SELECT
customer_counselor,
customer_university,
COUNT(DISTINCT customer_name) AS \'no of students\',
SUM(DISTINCT wll_invoice.total_payable) AS payable,**//I want to make total_payable should GROUP BY customer_id**
SUM(wll_invoice.total_pay) AS paid,
SUM(wll_invoice.due) AS balance
FROM
wll_customer
LEFT JOIN
wll_invoice ON wll_invoice.customer_id = wll_customer.customer_id
GROUP BY customer_counselor,customer_university;');
$payments = [];
foreach ($payments_ as $payment)
$payments[$payment->customer_counselor][$payment->customer_university] = $payment;
?>
<table id="table_id" class='display table-bordered'>
<thead>
<tr>
<td rowspan="2">Sl</td>
<td rowspan="2" >counselor</td>
<?php
foreach ($universities as $key => $university){ ?>
<td colspan="4" ><?=$university->customer_university ?> </td>
<?php } ?>
</tr>
<tr>
<?php foreach ($universities as $university){?>
<td>no of students</td>
<td>payable</td>
<td>paid</td>
<td>balance</td>
<?php } ?>
</tr>
</thead>
<tbody>
<tr>
<?php foreach ($counselors as $counselor){?>
<?php foreach ($universities as $key => $university){
$payment = $payments[$counselor->customer_counselor][$university->customer_university];
?> <?php if(!$key){?>
<td></td>
<td><?=$counselor->customer_counselor?></td>
<?php } ?>
<td><?=(int)$payment->{'no of students'}?></td>
<td><?=number_format($payment->payable,0,',','')?></td>
<td><?=number_format($payment->paid,0,',','')?></td>
<td><?=number_format($payment->balance,0,',','')?></td>
<?php } ?>
</tr>
<?php } ?>
</tbody>
</table>
哪個驅動程序不工作?什麼是錯誤信息? – bwoebi
這是好的如果你可以請幫助我與我的查詢 – Sha
這不是我的問題的答案?? – bwoebi