我在SQL数据库中有这个表
Acc ID Perod1 Perod2 Perod3 Perod4 Perod5
---------------------------------------------------
1-001 30 40 70 80 70
2-002 50 60 80 60 70
3-004 60 70 80 50 40
我需要在给定范围内选择上面的“Perod”列 . 像“Perod1 to Perod3”或“Perod2 to Perod5” . 需要编写一个SQL select查询,它可以选择给定范围的列 . 请帮我 .
我需要SQL查询,如下所示
Select
Perod1, Perod2
from
tbl_accPeriod
where
AccID = '1-001'
但“Perod”列我应该能够动态提供 . 有一次它可以是“Perod1到Perod2”,下次应该是“Perod1到Perod4” . 我想这样做而不添加IF条件 .
1 回答
我想你应该试试这个,