-1

我在执行 linq to sql 查询时遇到问题。请看一看。

这是我的代码:

    SELECT c.client_name,
       n.instrument_group_id,
       n.trade_date,
       sum(n.buy_qty) AS TotBuyQty,
       sum(convert(float,n.buy_value) + convert(float,n.buy_brokerage)) AS TotBuyVal,
       sum(n.sell_qty) AS TotSellQty,
       sum(convert(float,n.sell_value) - convert(float,n.sell_brokerage)) AS TotSellVal,
       sum(convert(float,n.sell_value) - convert(float,n.sell_brokerage))- sum(convert(float,n.buy_value) + convert(float,n.buy_brokerage)) AS ProfitLoss
FROM nse_fo_transaction AS n
LEFT JOIN client_master AS c ON n.client_id = c.client_id
WHERE n.client_id = 5
  AND n.trade_date BETWEEN '09/01/2012' AND '09/19/2012'
GROUP BY c.client_name,
         n.instrument_group_id,
         n.trade_date
ORDER BY n.trade_date
4

2 回答 2

0

这个怎么样?

from d in dps_admin_user
join c in dps_admin_role on d.user_id equals c.user_id into gcs
from c2 in gcs.DefaultIfEmpty()
group d.firstname by c2.parent_id into gfns
where gfns.Any()
orderby gfns.Count()
select gfns

我只是把它放在 LINQPad 中。我必须说不是很有意义,但它包含您所需的运算符。

为什么需要这样的例子?


这大致是您想要的查询。我无法测试它,但它应该相当接近。

var query =
    from n in nse_fo_transaction
    where n.client_id == 5
    where n.trade_date >= d0 && n.trade_date < d1
    join c0 in client_master on n.client_id equals c.client_id into cs
    from c in cs.DefaultIfEmpty()
    group new { n, c } by new
    {
        c.client_name,
        n.instrument_group_id,
        n.trade_date,
    } into gs
    orderby gs.Key.trade_date
    select new
    {
        gs.Key.client_name,
        gs.Key.instrument_group_id,
        gs.Key.trade_date,
        TotBuyQty = gs.Sum(x =>
            (float)x.n.buy_qty),
        TotBuyVal = gs.Sum(x => 
            (float)x.n.buy_value
            + (float)x.n.buy_brokerage),
        TotSellQty = gs.Sum(x => 
            (float)x.n.sell_qty),
        TotSellVal = gs.Sum(x =>
            (float)x.n.sell_value
            - (float)x.n.sell_brokerage),
        ProfitLoss = gs.Sum(x =>
            (float)x.n.sell_value
            - (float)x.n.sell_brokerage
            - (float)x.n.buy_value 
            + (float)x.n.buy_brokerage)
    };
于 2012-09-19T04:06:11.437 回答
0
Dim query = (From n In tblNseFo.AsEnumerable _
                            Where n!client_id = intClientID _
                            Group Join c In tblClient _
                            On n!client_id Equals c!client_id Into cs = Group _
                            From c In cs.DefaultIfEmpty _
                            Group n, c By _
                            c!client_name, n!instrument_group_id, n!trade_date Into gs = Group _
                            Order By trade_date _
                            Select New With { _
                                .client_name = client_name, _
                                .instrument_group_id = instrument_group_id, _
                                .trade_date = trade_date, _
                                .TotBuyQty = gs.Sum(Function(x) x.n!buy_qty), _
                                .TotSellQty = gs.Sum(Function(x) x.n!sell_qty), _
                                .TotBuyVal = gs.Sum(Function(x) x.n!buy_value) + gs.Sum(Function(x) x.n!buy_brokerage), _
                                .TotSellVal = gs.Sum(Function(x) x.n!sell_value) - gs.Sum(Function(x) x.n!sell_brokerage), _
                                .ProfitLoss = (gs.Sum(Function(x) x.n!sell_value) - gs.Sum(Function(x) x.n!sell_brokerage)) - _
                                              (gs.Sum(Function(x) x.n!buy_value) + gs.Sum(Function(x) x.n!buy_brokerage))})
于 2012-09-23T11:59:20.103 回答