2013-02-28 55 views
-1

我有以下议案表如何风格sqlite的选择

building  flatname flatdescription amount  pastpayments  receiptno 
1234   name a  a     123   0    0 
1234   name a  a     12   10    39 
1234   name a  a     125   125    40 
1235   name a  a     133   10    41 
1235   name b  b     125   125    50 
1234   name c  c     100   90    0 

我想选择行是金额减去支付大于零与buildingcode 1234与B型显示它们是否有receiptno> 0中相同的名字,如果有同名

内没有receiptno> 0无样式,以便从我的代码的结果必须是遵循

  name a  39 with style B 
     name c  0 

我怎样才能做到这一点?

我用下面的代码,但我收到的所有的选择,没有风格

  t.executeSql('SELECT receiptno AS mr, flatdescription, flatname, buildingcode FROM bill WHERE amount - pastpayments> 0 AND buildingcode = ? GROUP BY buildingcode, flatname ORDER BY flatdescription DESC',[buildingcode], function(t, resultflat) { 


      var i, 
       len = resultflat.rows.length, 
       row; 

      if (len > 0) { 
       items.push('<br>'); 
       for (i = 0; i < len; i += 1) { 
        row = resultflat.rows.item(i); 

        if (row.mr > 0) { 

         items.push('<li data-theme="b" data-icon="false" style="height:40px; padding: 7px 0 0 0; font-size: 1.2em"><a href="#displayflat" data-flat="' + row.flatname + '" data-description="' + row.flatdescription + '">' + row.flatdescription + '...' + row.flatname + '</a></li>'); 

         } else { 
         items.push('<li data-icon="false" style="height:40px; padding: 7px 0 0 0; font-size: 1.2em"><a href="#displayflat" data-flat="' + row.flatname + '" data-description="' + row.flatdescription + '">' + row.flatdescription + '...' + row.flatname + '</a></li>'); 

         } 
       } 
      } 

回答

0

有迹象表明,有building=1234flatname='name a'组中的多个记录。 只要说receiptno会给你一些的值随机其中的一条记录。

您可能想要使用MAX(receiptno)来获得组中最大的值;这可确保在组中有一个非零的receiptno