相关疑难解决方法(0)

计算PostgreSQL中的累积和

我想找到累积或运行的字段数量,并将其从分段插入表格.我的暂存结构是这样的:

ea_month    id       amount    ea_year    circle_id
April       92570    1000      2014        1
April       92571    3000      2014        2
April       92572    2000      2014        3
March       92573    3000      2014        1
March       92574    2500      2014        2
March       92575    3750      2014        3
February    92576    2000      2014        1
February    92577    2500      2014        2
February    92578    1450      2014        3          
Run Code Online (Sandbox Code Playgroud)

我希望我的目标表看起来像这样:

ea_month    id       amount    ea_year    circle_id    cum_amt
February    92576    1000      2014        1           1000 
March       92573    3000      2014        1           4000
April       92570    2000      2014        1           6000
February    92577    3000      2014 …
Run Code Online (Sandbox Code Playgroud)

sql postgresql analytic-functions cumulative-sum window-functions

62
推荐指数
1
解决办法
6万
查看次数

如何将"字符串"转换为"没有时区的时间戳"

我是Postgresql的新手,我正在使用WCF服务.
这是我的代码片段:

$.ajax({
    url: '../Services/AuctionEntryServices.svc/InsertAuctionDetails',
    data: JSON.stringify({ "objAuctionEntryEntity": {
        "AuctionNO": '',          
        "AuctionDate": $('[Id$="lblAuctionDateVal"]').text(),
        "TraderID": $('[Id$="ddlTraderName"] option:selected').val(),
        "Grade": $('[Id$="ddlGrade"] option:selected').val(),
        "Varity": $('[Id$="ddlVarity"] option:selected').val(), 
        "QuntityInAuction": $('#txtQuantityForAuction').val(),
        "AuctionRate": $('#txtAuctionRate').val(),
        "BrokerID": a[0],
        "IsSold": $('#chlIsSold').is(':checked'),
        "CreatedBy": $.parseJSON(GetCookie('Admin_User_In_Mandi')).UserID,
        "UpdatedBy": $.parseJSON(GetCookie('Admin_User_In_Mandi')).UserID,
        "CreationDate": GetCurrentDate().toMSJSON(),
        "IsActive": true,
        "AuctionTransaction": arrAuctionTransaction,
        "MandiID": $.parseJSON(GetCookie('Admin_User_In_Mandi')).MandiID,
        "FarmerID": _ownerid,
        "AuctionNO": _auctionno,
        "AmmanatPattiID": _ammantpattiid,
        "ToTraderID": b[0],
        "ToTraderName": $('#txtOtherBuyerNameEN').val(),
        "ToTraderName_HI": $('#txtOtherBuyerNameHI').val()
    }
}),
    type: 'POST',
    contentType: 'application/json',
    dataType: 'json'              
});
Run Code Online (Sandbox Code Playgroud)

这里:

$('[Id$="lblAuctionDateVal"]').text() = "20/8/2013 14:52:49" 
Run Code Online (Sandbox Code Playgroud)

我的这个领域的数据类型是timestamp without time zone.
如何将此字符串转换为timestamp without time zone数据类型?

javascript postgresql ajax wcf jquery

23
推荐指数
2
解决办法
5万
查看次数

在Rails + Postgres中按任意时间间隔计算记录的最佳方法

我的应用程序有一个Events带有时间戳事件的表.

我需要在每个最近的N时间间隔内报告事件的数量.对于不同的报告,间隔可以是"每周"或"每天"或"每小时"或"每15分钟间隔".

例如,用户可以显示他们每周,每天,每小时或每季度收到的订单数量.

1)我的偏好是动态地执行单个SQL查询(我正在使用Postgres)按任意时间间隔进行分组.有没有办法做到这一点?

2)一种简单但丑陋的暴力方法是对按时间戳排序的开始/结束时间帧内的所有记录执行单个查询,然后使用方法按任意间隔手动构建计数.

3)另一种方法是在事件表中为每个区间添加单独的字段并静态存储一个the_week the_day,the_hourthe_quarter_hour字段,这样我就可以在创建记录时(一次)进行"点击",而不是每次报告该字段时.

这里有什么最好的做法,因为我可以根据需要修改模型和预先存储间隔数据(尽管只需要将表格宽度加倍);

sql postgresql ruby-on-rails aggregate-functions generate-series

21
推荐指数
1
解决办法
5161
查看次数