是否有任何SQL查询生成按时间间隔排列的列。
查看示例图片:
答案 0 :(得分:0)
尝试:
select animal, DECODE(MOD(rownum,2), 0,'NO', 'YES') from your_table
答案 1 :(得分:0)
DECLARE @table TABLE ( Id INT IDENTITY(1,1) ,Animal VARCHAR(20))
INSERT into @table(Animal)
Select 'Fox'
Union
Select 'Dog'
Union
Select 'Fish'
Union
Select 'Bear'
Select [Animal] ,Case When ID%2 <>0 Then 'Yes' else 'No' END [AutoGenerateValue] FRom @table
答案 2 :(得分:0)
如果表中没有ID,则可以对ROW_NUMBER进行模数检查。
如果您的数据库仍然支持窗口功能。
select
animal,
(case
when (row_number() over (order by animal) % 2) = 1 then 'Yes'
else 'No'
end) as AutoGenerateValue
from animals