我在这里不能正确使用struct LinkedNode
{
long data;
LinkedNode* next;
};
class LinkedList
{
public:
LinkedList();
~LinkedList();
LinkedNode* head;
long Count;
long * Data;
void add(long data);
void update();
//long get(long index);
};
LinkedList::LinkedList(){
this->Count = 0;
this->head = NULL;
}
LinkedList::~LinkedList(){
LinkedNode * temp;
while(head){
temp= this->head ;
head = head->next;
delete temp;
}
if (Data)
delete [] Data; Data=NULL;
}
void LinkedList::add (long data){
LinkedNode * node = new LinkedNode();
node->data = data;
node->next = this->head;
this->head = node;
this->Count++;}
void LinkedList::update(){
this->Data= new long[this->Count];
long i = 0;
LinkedNode * node =this->head;
while(node){
this->Data[i]=node->data;
node = node->next;
i++;
}
}
,为什么GROUP BY
无法获取预期的结果。
我无法处理表GROUP BY
和fee
之间的联接。将fee_tm
分配给一个时,一个就可以了,但是根据上表的总行(已将ID分组)提取了另一个行。我曾尝试将GROUP BY
分配给这两者,但输出都被加倍了。
预期产量
实际结果
但是这里的行相应地重复了group_by
总行,然后将输出提取为
数据库结构
fee_tm
fee_tm.id
费用
id | ttl | year
=====================
1 | Jan | 1
2 | Feb | 1
3 | Mar | 1
cls_fee
id | ttl | year
========================
1 | Annual | 1
2 | Monthly | 1
学生
id | cls_id | sec_id | fee_id | fee
================================================
1 | 1 | 1 | 1 | 1000
2 | 1 | 1 | 2 | 560
MYSQL
id | ttl | cls | sec | year
====================================
1 | John| 1 | 1 | 1
2 | Riya| 1 | 1 | 1
$result=$con->prepare("
SELECT
fee_tm.ttl AS f_tm,
cls_fee.fee AS f_mnt,
fee.ttl AS f_ttl
FROM
student
LEFT JOIN
fee_tm ON fee_tm.year = student.year
JOIN
cls_fee ON cls_fee.sec_id = student.sec AND cls_fee.cls_id = student.cls
LEFT JOIN
fee ON fee.id = cls_fee.fee_id
WHERE
student.id =:stdt
GROUP BY
fee_tm.id";
$results=array();
while($row=$result->fetch(PDO::FETCH_ASSOC)){
$results[]=$row;
echo"
<input type='checkbox' name='f_id' /'>".$row['f_tm'];
} echo "<br/>
<table>";
foreach($results as $row1){
echo"
<tr>
<td>".$row1['f_ttl']."</td>
<td>".$row1['f_mnt']."</td>
</tr>";
} echo "</table>";
的结果:
print_r($result->fetchAll(PDO::FETCH_ASSOC))