比较两列,只选择一个用sql查询

时间:2018-01-23 05:33:30

标签: sql linq case

我有两列,让我们说col1col2。它们都是float

总是if col1 = 0 then col2 > 0col1 > 0 then col2 = 0

我只想选择一个大于零的列。

提前致谢

4 个答案:

答案 0 :(得分:1)

试试这个:

<ng-template #showInput>
        <div class="col-md-8 " [ngSwitch]="fieldInfo.dataTypeName">
                <input *ngSwitchCase="'Text'" class="form-control" [(ngModel)]="pageInfoBeans.nameValueMap[fieldInfo.name]" name="{{fieldInfo.name}}"
                        [required]="fieldInfo.requiredInd" [maxLength]="fieldInfo.fieldSize==0?5:fieldInfo.fieldSize" [disabled]="formEnableInd">

                <input *ngSwitchCase="'Email Address'" type="email" class="form-control" [(ngModel)]="pageInfoBeans.nameValueMap[fieldInfo.name]" name="{{fieldInfo.name}}"
                        [required]="fieldInfo.requiredInd" [maxLength]="fieldInfo.fieldSize==0?5:fieldInfo.fieldSize" [disabled]="formEnableInd"></ng-template>

答案 1 :(得分:0)

其中一个总是零?

SELECT col1+col2

答案 2 :(得分:0)

您也可以使用:

SELECT CASE WHEN Col1 > 0 THEN COL1 ELSE Col2 END from your_table

答案 3 :(得分:0)

您可以将此用于linq

from t in Table
select new { Col = ( t.col1  > 0 )?t.col1 : t.col2  }
相关问题