我想从附合条件的记录中随机选择一条,SQL应怎么写???
下边是我写的SQL,但不知道具体怎么写..高手指教 Select top N * from Hover_Products where PClass ='" + BCNews_Name + "' and Product_t='1' order by id desc
...全文
33715打赏收藏
SQL随机选 择一条记录????????????
我想从附合条件的记录中随机选择一条,SQL应怎么写??? 下边是我写的SQL,但不知道具体怎么写..高手指教 Select top N * from Hover_Products where PClass ='" + BCNews_Name + "' and Product_t='1' order by id desc
[Quote=引用 1 楼 guoyz_1 的回复:]
Select top N * from Hover_Products where PClass ='" + BCNews_Name + "' and Product_t='1' order by NEWID()
[/Quote]
Mark NEWID()
[Quote=引用 8 楼 guoyz_1 的回复:]
引用 1 楼 guoyz_1 的回复:
Select top N * from Hover_Products where PClass ='" + BCNews_Name + "' and Product_t='1' order by NEWID()
你的N是不是变量, 放在查询分析器里面
应该写成
引用 1 楼 guoyz_1 的回复:
Select top 10 * from Hover_Products where PClass ='" + BCNews_Name + "' and Product_t='1' order by NEWID()
[/Quote]
是在不行
Select * from Hover_Products where PClass ='" + BCNews_Name + "' and Product_t='1'
再不行 就是 lz。。。。哼哼
[Quote=引用 5 楼 dys_198102 的回复:]
Select top N * from Hover_Products where PClass ='Garden Fun' and Product_t='1' order by NEWID()
消息102,级别15,状态1,第1 行
'N' 附近有语法错误。我在查询中直接给值测试..不行.
[/Quote]
[Quote=引用 5 楼 dys_198102 的回复:]
Select top N * from Hover_Products where PClass ='Garden Fun' and Product_t='1' order by NEWID()
消息102,级别15,状态1,第1 行
'N' 附近有语法错误。我在查询中直接给值测试..不行.
[/Quote]
top 后面必须是数字,写N肯定会报错