10在同一SQL查询上运行的值

时间:2018-06-14 10:42:43

标签: sql-server

我的数组中有10个值,我正在为每个数组循环查询。有没有办法在没有循环的情况下将它放在一个语句中?

activity_df['new'] = activity_df['duration'].where(activity_df['activities']=='sleep').ffill()
print (activity_df)
   activities  duration   new
0        work         1   NaN
1        home         5   NaN
2       sleep        11  11.0
3        home         8  11.0
4        work        11  11.0
5       sleep         8   8.0
6        work         9   8.0
7        home        13   8.0
8       sleep        19  19.0
9        home         6  19.0
10       work        19  19.0
11      sleep        16  16.0
12       work        16  16.0
13       home         1  16.0
14       work         5  16.0
15      sleep        10  10.0
16       work         1  10.0
17       home         5  10.0
18       work         0  10.0
19      sleep         4   4.0
20       work        12   4.0
21       home         4   4.0
22       work        10   4.0
23      sleep         6   6.0
24       work        17   6.0
25       home        14   6.0
26       work         7   6.0
27       home         5   6.0
28       work        10   6.0
29      sleep         8   8.0

1 个答案:

答案 0 :(得分:0)

SELECT
    a.OrderSuffix AS 'OrderSuffix',
    COUNT(1) AS 'CountNew'
FROM
    dbo.Orders AS a,
    dbo.OrderStatus AS b
WHERE
    b.Status = 'Finished' AND
    a.OrderSuffix IN ('ABC', 'DEF', 'HIJ')
GROUP BY
    a.OrderSuffix