2013-02-28 86 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