【问题标题】:random fetch display data to dropdownlist随机获取显示数据到下拉列表
【发布时间】:2012-02-07 00:43:52
【问题描述】:

基本上我希望在下拉列表中随机显示项目,任何功能都可以使用它吗?

输出

一个

b

c

预期输出(可以是任何但不仅是 abc)

b

一个

c

c

一个

b

任何


asp:Label ID="Label3" Text=' ' Runat="server"


Select * from (SELECT [r1] AS [Option] FROM [ExerciseTable] WHERE ([Question] = @Question)

UNION SELECT [r2] AS [Option] FROM [ExerciseTable] WHERE ([Question] = @Question) UNION

SELECT [r3] AS [Option] FROM [ExerciseTable] WHERE ([Question] = @Question AND

[r3]!=null))t 按 Newid()" 排序

【问题讨论】:

  • 有吗?按 Desc 订购可以吗?
  • erm,按 desc 排序不是我想要的,我想要的是随机输出>

标签: c# asp.net


【解决方案1】:

您可以使用Newid() 获取随机顺序

SELECT *
FROM   (SELECT [r1] AS [Option]
        FROM   [ExerciseTable]
        WHERE  ( [Question] = @Question )
        UNION
        SELECT [r2] AS [Option]
        FROM   [ExerciseTable]
        WHERE  ( [Question] = @Question )
        UNION
        SELECT [r3] AS [Option]
        FROM   [ExerciseTable]
        WHERE  ( [Question] = @Question
                 AND [r3] != NULL )) t
ORDER  BY Newid()  

更新

测试:

代码:

SELECT *
FROM   (SELECT 'a' AS col
        UNION
        SELECT 'b' AS col
        UNION
        SELECT 'c' AS col) t
ORDER  BY Newid()  

第一次

第二次

【讨论】:

  • 你应该得到随机顺序。
猜你喜欢
  • 1970-01-01
  • 2021-10-19
  • 2015-05-22
  • 1970-01-01
  • 1970-01-01
  • 2020-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多