Classic SQL data statistics

zhaozj2021-02-16  106

There are two tables: Table V records the number of input and exit in each ID (entering positive, outgoing), and Table B records the remainder of each ID.

Table V Table BID RQ Extraction CTC ID RQ Hosts CTC1 2004-05-10 100 11 1 2004-05-10 100 11 1 2004-05-15 -20 11 1 2004-05-15 80 112 2004-05-10 200 11 2 2004-05-12 50 112 2004-05-12 250 11 2 2004-06-02 -100 11 2 2004-06-02 150 113 2004-05-12 50 13 3 2004 -05-12 50 133 2004-05-20 -10 13 3 2004-05-20 40 13

Now I want to count the number of pits in each CTC in a certain period of time RQ1 to RQ2, the expenditure, the remainder, for example, to get the results of each CTC between 2004-05-10 to 2004-05-20, as follows : CTC RQ enters the rest of the number (the sum of the sum of the number) (the sum of the sum of the number of negative values) (ID corresponds to the maximum date of the maximum date)

11 2004-05-10 300 0 300 11 2004-05-12 50 0 35011 2004-05-15 0 20 33013 2004-05-12 50 0 5013 2004-05-20 0 10 40

Answer (9CBS Zou Jianxing)

- Query parameter definition declare @ dt1 datetime, @ DT2 datetimeselect @ dt1 = '2004-05-12', @ DT2 = '2004-05-20'

转载请注明原文地址:https://www.9cbs.com/read-11091.html

New Post(0)