-1

linqtosqlクエリの実行に問題があります。ご覧ください。

これが私のコードです:

    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
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 に答える
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 に答える