分组并过滤多个列

时间:2017-08-04 15:52:45

标签: c# linq

我试图从存储过程中过滤结果集(使用Linq)。

返回的数据如下所示:

+---------+------+-------+-------+-------+-------+  
| Customer| Item | Week1 | Week2 | Week3 | Week4 |  
+---------+------+-------+-------+-------+-------+  
| A       |    1 | NULL  | NULL  | NULL  | NULL  |  
| A       |    2 | NULL  | NULL  | NULL  | NULL  |  
| B       |    1 | NULL  | M     | NULL  | NULL  |  
| B       |    2 | M     | NULL  | E     | NULL  |  
| C       |    1 | NULL  | NULL  | NULL  | NULL  |  
| C       |    2 | M     | NULL  | NULL  | M     |  
+---------+------+-------+-------+-------+-------+  

我试图过滤掉所有项目的所有周列中包含NULL的客户。在这种情况下,我想过滤掉客户A的行,但列出客户B和C的所有行和列。完整的结果集将是几百个客户和几千个项目。

我已将数据分组到一起,但我实际上删除了我不想要的项目时遇到了麻烦。

custEvents.GroupBy(
ce => new
{
    custId = ce.companyID,
    week1 = ce.wk1eventId,
    week2 = ce.wk2eventId,
    week3 = ce.wk3eventId,
    week4 = ce.wk4eventId
}
).OrderBy(ce => ce.Key.custId);  

3 个答案:

答案 0 :(得分:3)

import pygame, sys


pygame.init()

red = (255,0,0)
black = (0,0,0)
white = (255,255,255)
blue = (0,0,255)

pygame.mouse.set_visible(0)
clock = pygame.time.Clock()

displaySize = (800,600)

screen = pygame.display.set_mode(displaySize)

g = 30
dt = 0.05

class ball:
    def __init__(self, x, y, vx, vy, r,ax,ay, color):

        dt = 0.05

        Cd = 0.01
        m = 5

        self.ay = ay
        self.ax = ax

        self.x = x
        self.y = y
        self.r = r
        self.color = color

        self.vx = vx
        self.vy = vx

def update(self, x, y):


    x, y = physics()
    pygame.draw.circle(screen, self.color, (int(round(x)),int(round(y))), self.r)
    pygame.display.update()

    def physics(self):


        self.Dy = Cd*self.vy*abs(self.vy)
        self.Dx = Cd*self.vx*abs(self.vx)

        self.Fy = self.m*g - self.Dy
        self.Fx = -self.Dx

        self.ay = self.Fy/m
        self.ax = self.Fx/m

        self.vy += self.ay*dt
        self.vx += self.ax*dt

        self.x +=self.vx*dt
        self.y +=self.vy*dt

        return self.x, self.y

one = ball(100,100,0,0,0,0,30,red)

while 1:
    clock.tick(30)
    screen.fill(blue)
    one.update()

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

答案 1 :(得分:1)

听起来您希望按客户分组并获取具有任何非空周记录的组:

{
  "rules": {
    ".read": true,
    ".write": true
  }
}

答案 2 :(得分:0)

订购后可以随时删除。

custEvents.RemoveAll(x => x.Customer = "A" && x.week1 = null && x.week2 = null && x.week3 = null && x.week4 = null);