2016-10-02 51 views
0

我嘗試這樣的代碼輸出這個(正確的輸出)集團兩米欄和獨特的

enter image description here

但它給了我這個是錯的輸出 enter image description here

我需要不同的名稱,按品牌對產品進行分組,但沒有發生在我的查詢中,請參閱上面的圖片。

$datefilter=mysqli_query($link,"select 
     SUM(INVOICE_ITEM_AMOUNT_MX) AS totalamount, 
     INVOICE_NO_MX, 
     INVOICE_CUSTOMER_NAME 
     ,INVOICE_DATE_MX,ITEM_BRAND_MX 
     ,GROUP_CONCAT(INVOICE_ITEM_CODE_MX SEPARATOR '<BR>') as itemcode 
      ,GROUP_CONCAT(INVOICE_ITEM_QTY_MX SEPARATOR '<BR>') as quantity 
      ,GROUP_CONCAT(INVOICE_ITEM_UPRICE_MX SEPARATOR '<BR>') as price 
      ,GROUP_CONCAT(INVOICE_ITEM_SERIAL_MX SEPARATOR '<BR>') as serial 
        ,GROUP_CONCAT(DISTINCT (INVOICE_SALES_REP_MX) SEPARATOR '<BR>') as salesrep 

      ,GROUP_CONCAT(DISTINCT (ITEM_BRAND_MX) SEPARATOR '<BR>') as brand   
    from invoice where INVOICE_DATE_MX BETWEEN '" .$datefrom. "' AND '" . $dateto ."' and 
    BRANCH_CODE_MX='".$display_branchcode."' AND INVOICE_STATUS_MX='PAID' GROUP BY INVOICE_SALES_REP_MX,ITEM_BRAND_MX "); 

    $count=mysqli_num_rows($datefilter); 
     echo '<div class="col-xs-12"> 

        <br> 
        <div class="col-xs-6"> 
    <label> Total Invoice Number: </label> '.$count.' 
     </div> 
     <div class="col-xs-6"> 
    <label> Date Range: </label> '.$convertedfrom.' - '.$convertedto.' 
     </div> 
     </div>';    

     while($daterow=mysqli_fetch_array($datefilter)){ 
            $date=$daterow["INVOICE_DATE_MX"]; 
          $customername=$daterow["INVOICE_CUSTOMER_NAME"]; 
          $invoiceref=$daterow["INVOICE_NO_MX"]; 
          $salesrep=$daterow["salesrep"]; 
          $itemcode=$daterow["itemcode"]; 
          $imeiserial=$daterow["serial"]; 
          $totalnotformat=$daterow["totalamount"]; 
          $upricenotformat=$daterow["price"]; 
          $quantity=$daterow["quantity"]; 
          $itembrand=$daterow["brand"]; 

         $total=number_format($totalnotformat,2); 
         $uprice=number_format($upricenotformat,2);    
     echo' 
    <div class="col-xs-12"> 
        <br> 
        <div class="panel panel-warning"> 
     <div id="shade" class="panel-body"><label>'.$salesrep.'</label></div> 
     <div id="shade" class="panel-body"> 
    <div class="col-xs-10"> 
    <div class="col-xs-4">'; 
    echo ' 
    <label>Brand</label>: '.$itembrand.'<br> 
    <div class="col-xs-7"> 
    <label>Item Code</label> <br>'.$itemcode.' 

    </div> 
    <div class="col-xs-1"> 
    <label> Quantity</label> <br>'.$quantity.' 

    </div> 
    </div>    
    </div>   
     </div> 
+1

的一個好辦法問一個MySQL的問題是顯示輸入數據,查詢,和預期產出,以及您當前的產出。 –

+0

一個正確的查詢我的問題:( –

+0

我已經給它 –

回答

1

我想,下面的應該幫助,哪些是你想我的意思是,以顯示不同的名稱。但是你可以用PHP做到這一點很容易:

SELECT CASE WHEN t.id = (SELECT t2.id FROM process t2 
WHERE t2.projectNo = t.projectNo 
GROUP BY t2.projectNo LIMIT 1) THEN t.projectNo 
ELSE 
'' 
END AS Deatils, t.stuff 
FROM process t 

樣品的輸入和輸出:

mysql_distinct

mysql_distinct_02

+0

不適合我 –

+0

我猜,你有一個單一的表。該表並根據您的更改列。 –