1

ヘジ

私の SQL スキルは非常に限られているため、助けが必要です。

Azure MobileService テーブルに、人々が投票できる要素のテーブルがあります。次のようになります。

テーブル名


                                   ID | Content | Votes |

このテーブルから、投票数が最も多い 20 個の要素を取得したいと思います。いくつかが同じ票を持っている場合は、これらのいずれかを選択する必要があります。最適なのは、MobileService API への GET ポストを使用して上位の投票範囲を選択できることでした。このような新しい呼び出しは、次の 20 要素を取得します。

Azure の API は次のようになります。

    exports.get = function(request, response) { 
        //some code
        response.send();
    }

そして、によって呼び出すことができます

    var results = await App.MobileService.InvokeApiAsync<Class>("APIname", System.Net.Http.HttpMethod.PostorGet, DictionaryOfInformationSendToTheAPI);

だから私が望むのは、HttpMethod.Get コマンドを送信することです。ここで、辞書に必要な範囲を API 呼び出しに送信します。API 呼び出しは、ID または行全体を返すことによって、テーブルtableNameから情報を取得することで応答します。

方法がわからないので、最大のものを取得するための推測にすぎませんが、誰かがこのコマンドの作成を手伝ってくれることを願っています。

    exports.get = function(request, response) { 
    //Not working so just a guess
        var sqlSpecs = "READ from tableName WHERE votes is" + request.rangeMax + " to " + request.rangemin;
        mssql.query(sqlSpecs, {
         success: function(items)
            {
                console.log("ok");
                response.send(items);
            },
            error: function(err)
            {
                console.log("there was a problem finding the Specified range" + request.rangeMax + " to " + request.rangemin, "" + err);
            }
        });
    }

最後に、私はもちろん、よりスマートにアクセスする方法の他のアイデアをオープンにしています. たぶん、トップ 20 の余分なテーブルですか? しかし、私にとっての問題は、インフラストラクチャがはるかに大きくなるため、SQL コマンドをよりスマートにする必要があると考えたことです。しかし、アイデアとともに参加してください。

4

2 に答える 2

1
exports.get = function(request, response) {    
    var collectionOfVotes = request.service.tables.getTable('CollctionOfVotes');
    collectionOfVotes.orderByDescending('Votes')
    .read({ success: function(results) { 
        results.forEach(function(r) {
                console.log(r);
            });
    }});
};

or

exports.get = function(request, response) 
{    
    mssql.query('select top 20 * from CollctionOfVotes order by Votes desc', 
    {
      success: function(results) 
      {
            results.forEach(function(r) {
                console.log(r);
            });
      },
      error: function(err) 
      {
                console.log("error is: " + err);
      }
   });
}
于 2013-10-02T12:58:31.527 に答える
1

次のようにテーブルにアクセスできます。

exports.get = function(request, response) {    
    var myTable = request.service.tables.getTable('tableName');
    // Do something with the table here…
};

または、実行している方法とまったく同じ方法でクエリを実行できます。

exports.get = function(request, response) 
{    
    mssql.query('select top 20 * from tablename', 
    {
      success: function(results) 
      {
         console.log(results);
      },
      error: function(err) 
      {
                console.log("error is: " + err);
      }
   });
}
于 2013-09-30T16:52:28.330 に答える