检查SQL表中所有先前行的值

时间:2017-06-05 09:28:20

标签: sql sql-server sql-server-2014

我有以下SQL表:

declare @t table(START_DATE datetime,INDEX_ID int, GROSS_SALES_PRICE decimal(10,2));
insert into @t values
 ('20150619',10000410,38)
,('20170311',10000410,26.49)
,('20170312',10000410,26.49)
,('20170317',10000410,38)
,('20170318',10000410,38)
,('20170321',10000410,38);

我想检查GROSS_SALES_PRICE

中是否有任何临时更改

例如,在此表格中,我的价格为38,然后我有两行26.49,然后再次38。可以有任意数量的低价行,所以我认为我必须检查多个前一行?

如果发生这种情况,我想制作值为1的第三列:

Table 2

1 个答案:

答案 0 :(得分:1)

public class PermissionDialogManager extends DialogFragment {  

    public static PermissionDialogManager newInstance(Bundle bundle) {
        PermissionDialogManager frag = new PermissionDialogManager();
        frag.setArguments(bundle);
        return frag;
    }    

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        ...
    }
} 
INDEX_ID | GROSS_SALES_PRICE | CHANGED
-------: | :---------------- | ------:
10000410 | 38.00             |       0
10000410 | 26.49             |       1
10000410 | 26.49             |       1
10000410 | 38.00             |       0
10000410 | 38.00             |       0
10000410 | 38.00             |       0

dbfiddle here