随即抽取问题可以用
select top 1 * from tableA order by newID()得到时间可以用
select getdate()
select top 1 * from tableA order by newID()得到时间可以用
select getdate()
解决方案 »
- 在sql server 中如何返回我所查询到的记录数目
- 请问mssql的日志log文件到底有什么用处?
- 一句创建序列的语句的问题
- 一个几百万条的Insert,用多线程实现是否比单线程快?
- 求一个SQL语句或过程:查出带条件的重复记录
- 急急急~~~!!新手问时间问题~困扰了好久了,不明白!!!解决马上给分!!(在线等)
- 高难度问题,高分,请进
- 请看一段测试代码,寻求解决方法.谢谢!
- 关于联接.....有如下数据,如何生成如下数据????(500分,分批给)
- 我怎么能在QA中用SELECT INTO语句? The database owner must run sp_dboption to enable this option.
- 一个菜鸟的问题,怎么样才能在视图中使用order by ?
- 我想了一个星期的问题!!高手请问? 就帮个忙吧
select * from (
select top 1 * from tableA where 难度='难' order by newID() ) a
union all
select * from (
select top 1 * from tableA where 难度='中' order by newID() ) a
union all
select * from (
select top 1 * from tableA where 难度='易' order by newID() ) a
2、如何在C\S结构下得到数据库服务器的当前时间(最好能给出C#中的实现代码)。
GETDATE
按 datetime 值的 Microsoft® SQL Server™ 标准内部格式返回当前系统日期和时间。语法
GETDATE ( )返回类型
datetime注释
日期函数可用在 SELECT 语句的选择列表或用在查询的 WHERE 子句中。在设计报表时,GETDATE 函数可用于在每次生成报表时打印当前日期和时间。GETDATE 对于跟踪活动也很有用,诸如记录事务在某一帐户上发生的时间。示例
A. 用 GET DATE 返回当前日期和时间
下面的示例得出当前系统日期和时间:SELECT GETDATE()
GO下面是结果集:-------------------------
July 29 1998 2:50 PM(1 row(s) affected)B. 在 CREATE TABLE 语句中使用 GETDATE
下面的示例创建 employees 表并用 GETDATE 给出员工雇佣时间的默认值。USE pubs
GO
CREATE TABLE employees
(
emp_id char(11) NOT NULL,
emp_lname varchar(40) NOT NULL,
emp_fname varchar(20) NOT NULL,
emp_hire_date datetime DEFAULT GETDATE(),
emp_mgr varchar(30)
)
GO
@1 int,
@2 int,
@3 int
asdeclare @a varchar(8000)
set @a='
select * from (
select top '+cast(@1 as varchar(10))+' * from tableA where 难度=''难'' order by newID() ) a
union all
select * from (
select top '+cast(@2 as varchar(10))+' * from tableA where 难度=''中'' order by newID() ) a
union all
select * from (
select top '+cast(@3 as varchar(10))+' * from tableA where 难度=''易'' order by newID() ) a
'
exec(@a)
@1 int,
@2 int,
@3 int
asdeclare @a varchar(8000)
set @a='
select * from (
select top '+cast(@1 as varchar(10))+' * from tableA where 难度=''难'' order by newID() ) a
union all
select * from (
select top '+cast(@2 as varchar(10))+' * from tableA where 难度=''中'' order by newID() ) a
union all
select * from (
select top '+cast(@3 as varchar(10))+' * from tableA where 难度=''易'' order by newID() ) a
'
exec(@a)
go--调用:exec procName 10,1,4
alter procedure sjsc
@a int,
@b int,
@c int
as
declare @g varchar(8000)
set @g='
select * from (
select top '+cast(@a as varchar(10))+' * from Question where que_difficulty='+'1'+' order by NEWID()) s
union all
select * from (
select top '+cast(@b as varchar(10))+' * from Question where que_difficulty='+'2'+' order by NEWID()) s
union all
select * from (
select top '+cast(@c as varchar(10))+' * from Question where que_difficulty='+'3'+' order by NEWID()) s
'
exec(@g)
goexec sjsc 1,1,1
我的表是
create table dbo.Question (
cou_no numeric(18) not null,
teau_no numeric(18) not null,
que_no numeric(18) not null,
que_type char(1) null
constraint CKC_QUE_TYPE_QUESTION check (que_type is null or ( que_type in ('1','2') )),
que_score real null,
que_difficulty char(1) null
constraint CKC_QUE_DIFFICULTY_QUESTION check (que_difficulty is null or ( que_difficulty = '3' or que_difficulty in ('1','2') )),
que_picture image null,
que_content text null,
que_createtime datetime null,
que_modifytime datetime null,
que_memo varchar(200) null,
constraint PK_QUESTION primary key clustered (que_no, teau_no, cou_no)
)
go
大力请帮忙看看,谢谢