我有这个代码输出表i中使用group by的值 将相同的项目代码分组,但序列不显示它只显示 onevalue 123321.输出应为123321,4354
$invoicequery=mysqli_query($link,"Select SUM(INVOICE_ITEM_QTY_MX),INVOICE_ID_MX,INVOICE_ITEM_UPRICE_MX,INVOICE_ITEM_AMOUNT_MX,INVOICE_ITEM_SERIAL_MX,INVOICE_ITEM_DESC_MX,INVOICE_ITEM_CODE_MX from invoice WHERE BRANCH_CODE_MX='".$display_branchcode."'
and INVOICE_NO_MX='".$invoicecode."' GROUP BY INVOICE_ITEM_CODE_MX");
while($row=mysqli_fetch_array($invoicequery))
{
$invoiceid=$row["INVOICE_ID_MX"];
$itemcode=$row["INVOICE_ITEM_CODE_MX"];
$itemquantity=$row['SUM(INVOICE_ITEM_QTY_MX)'];
$unitprice=$row["INVOICE_ITEM_UPRICE_MX"];
$amount=$row["INVOICE_ITEM_AMOUNT_MX"];
$serialimei=$row["INVOICE_ITEM_SERIAL_MX"];
$itemdescription=$row["INVOICE_ITEM_DESC_MX"];
}
答案 0 :(得分:0)
听起来你正在寻找MYSQL的GROUP_CONCAT()函数方法。只需将您希望返回的列名称包装为逗号分隔列表,就像使用了MAX()一样。
SELECT student_name,
GROUP_CONCAT(test_score)
FROM student
GROUP BY student_name;
这将返回,例如,
student_name | test_score Becky C. | 80,77,95
请注意,此值将根据您的数据库group_concat_max_len设置进行截断。