【问题标题】:Print value based on multiple column基于多列打印值
【发布时间】:2017-07-22 16:10:12
【问题描述】:

我的桌子

+----+----------+---------+---------+----------+
| ID | State A  | State B | State C | Duration |
+----+----------+---------+---------+----------+
| 1  |     a    |    a    |    a    |    12    |
+----+----------+---------+---------+----------+
| 2  |     a    |    a    |    a    |    15    |
+----+----------+---------+---------+----------+
| 3  |     a    |    a    |    b    |    12    |
+----+----------+---------+---------+----------+
| 4  |     a    |    b    |    b    |    30    |
+----+----------+---------+---------+----------+
| 5  |     b    |    b    |    b    |    12    |
+----+----------+---------+---------+----------+

如果 3 列具有相同的值和持续时间

+----+-----------------+
| ID |    THE RESULT   |
+----+-----------------+
|  1 | a is the winner |
+----+-----------------+

【问题讨论】:

  • 正如您所写:三列具有相同的值和持续时间:where stata_A = stateB and stateB = stateC amd duration < 15
  • 其他行呢
  • 您在寻找 linq 还是 SQL 解决方案?如果 linq 你有没有尝试过什么?
  • 然后将 WHERE 条件移动到 Select 中:case when stata_A = stateB and stateB = stateC and duration < 15 then 'is the winner' else '' end

标签: c# sql asp.net linq-to-sql


【解决方案1】:

这是一个过滤器以及concat():

select concat(statea, ' is the winner')
from t
where statea = stateb and stateb = statec and duration < 15

【讨论】:

  • if state a =1 if state b =1 state c=1 我想要一些文字出现
猜你喜欢
  • 1970-01-01
  • 2021-06-26
  • 2019-06-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-11
  • 2023-03-02
  • 1970-01-01
相关资源
最近更新 更多