将单列分成两列

时间:2016-03-01 09:55:24

标签: html css

如何在评论栏的基础上将付款栏分为退款和转帐费用?



<table>
<thead>
  <th>Payment</th>
  <th>comments</th>
  
  </thead>
  <tbody>
    <tr>
   <td>3000</td>
    <td>refund</td>
      </tr>
    
    <tr>
   <td>3000</td>
    <td>refund</td>
      </tr>
    
    <tr>
   <td>3000</td>
    <td>transfer fee</td>
      </tr>
  </tbody>
  
</table>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

按如下所示编写查询: -

SELECT payment AS PAYMENT,comments AS COMMENTS FROM TableName 
WHERE comments = 'refund' OR comments = 'transfer fee'

答案 1 :(得分:0)

你可能需要尝试这样的事情: -

SELECT SUM(fund), SUM(refund) FROM
    (
    SELECT
    payment, comments ,
    CASE  when (comments !='transfer fee'  )   then payment else '' end  As fund,
    CASE     when (comments !='refund'  )   then payment else '' end  As refund,
    FROM `tblname` ) tbl
WHERE tbl.comments = 'refund' OR tbl.comments = 'transfer fee'

内部查询使用CASE

使用相同列进行资金和退款
SELECT
    payment, comments ,
    CASE  when (comments !='transfer fee'  )   then payment else '' end  As fund,
    CASE     when (comments !='refund'  )   then payment else '' end  As refund,
    FROM `tblname`