【发布时间】:2019-11-18 15:20:31
【问题描述】:
如何从表存储中提取 MAX(值)? 例如,什么是
select MAX(Timestamp) FROM DailyUsers
(但 DailyUsers 是 Azure 表存储而不是 SQL 表)
【问题讨论】:
-
这能回答你的问题吗? How to get the highest value in Azure Table
如何从表存储中提取 MAX(值)? 例如,什么是
select MAX(Timestamp) FROM DailyUsers
(但 DailyUsers 是 Azure 表存储而不是 SQL 表)
【问题讨论】:
如果您使用的是 c# 代码,您可以按照以下步骤操作:
1.创建一个.net框架控制台项目,安装WindowsAzure.Storagenuget包,版本9.3.3。
2.为您的表存储定义一个entity class。如下代码,只是一个示例,您可以根据需要对其进行修改:
using Microsoft.WindowsAzure.Storage.Table;
namespace ConsoleApp6
{
public class CustomerEntity : TableEntity
{
public CustomerEntity()
{
}
public CustomerEntity(string lastName, string firstName)
{
PartitionKey = lastName;
RowKey = firstName;
}
public string FirstProperty { get; set; }
public string SecondProperty { get; set; }
}
}
3.然后在program.cs中,编写如下代码。而要获取最大日期记录,可以使用这行代码:OrderByDescending(r=>r.Timestamp).FirstOrDefault()。
program.cs 中的示例代码:
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;
using System;
using System.Linq;
namespace ConsoleApp6
{
class Program
{
static void Main(string[] args)
{
string connstr = "DefaultEndpointsProtocol=https;xxxxxx;EndpointSuffix=core.windows.net";
var storageAccount = CloudStorageAccount.Parse(connstr);
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
CloudTable table = tableClient.GetTableReference("your_table_name");
TableQuery<CustomerEntity> query = new TableQuery<CustomerEntity>();
//if you want to get the max date value from a specified PartitionKey, you can uncomment the following code.
//string myfilter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "r1");
//query.FilterString = myfilter;
var items = table.ExecuteQuery(query).OrderByDescending(r=>r.Timestamp).FirstOrDefault();
Console.WriteLine(items.PartitionKey+","+items.RowKey+","+items.Timestamp);
Console.ReadLine();
}
}
}
如果您有更多疑虑,请随时告诉我。
【讨论】:
RowKey ge '20170805' 可用于查询 RowKeys 大于等于 20170805。我只是想知道是否有查询,而不是 c# 项目,因为查询需要放入 json 文件(azure datafactory pipeline json)。