SELECT * FROM A WHERE SCORE='未考' or convert(int,SCORE) <60
解决方案 »
- 过程传参数
- 建表约束自动增长,急!在线等!
- openrowset问题,!!!!!!!!!
- 请问为什么不是最后一行对应的那一列的值
- 這樣的語句selet set Qty=if(Qty>RtQty, 1, 0) from Table 不能用,有沒有代替辦法?
- 为什么执行access数据库反比MS SQL快?
- 历史性奇怪问题:对一个表可以进行增添操作,但是不能进行修改、删除操作(一定给分)
- mssql中判断闰年的函数是什么
- 散分:谁能解决往SQL SERVER中数据库表中的IMAGE类型段中加数据(约50M)的超时问题
- 两条update语句在一个string里,执行时自动具有事务么?
- 帮忙看一下这个存储过程
- 关于网站sql数据库的配置问题,急!!!
表A的三个字段都为varchar类型的
name subject score
张三 语文 80
张三 数学 58
张三 物理 20
李四 语文 100
李四 物理 未考
李四 英语 76
李四 化学 作弊 要求查出所有小于60分和有作弊,未考的学生的科目
insert into tablename values('张三','数学','58')
insert into tablename values('张三','物理','20')
insert into tablename values('李四','语文','100')
insert into tablename values('李四','物理','未考')
insert into tablename values('李四','英语','76')
insert into tablename values('李四','化学','作弊')select * from tablename
select *
into #tmp
from tablename where score<>'未考' and score<>'作弊'select * from #tmp where convert(int,SCORE) < 60
union
select * from tablename where score='未考' or score='作弊'
where (case when isnumeric(score)=1 then score else 80 end)<60
or (case when isnumeric(score)=0 then score end)in('未考','作弊')
insert into tablename values('张三','数学','58')
insert into tablename values('张三','物理','20')
insert into tablename values('李四','语文','100')
insert into tablename values('李四','物理','未考')
insert into tablename values('李四','英语','76')
insert into tablename values('李四','化学','作弊')select * from tablename where SCORE='未考' or (case when ISNUMERIC(score)=1 then cast(score as int) end)<60
select * from #T
where (case when isnumeric(score)=1 then score end)<60
or score in('未考','作弊')
SELECT * FROM A
WHERE
(ASCII(LTRIM(RTRIM(Score))) >= 48) AND (ASCII(LTRIM(RTRIM(Score))) < 54)
OR
(LTRIM(RTRIM(Score)) IN ('作弊', '末考'))
WHERE (LTRIM(RTRIM(Score))<>'100' AND
(ASCII(LTRIM(RTRIM(Score))) >= 48) AND (ASCII(LTRIM(RTRIM(Score))) < 54)
OR
(LTRIM(RTRIM(Score)) IN ('作弊', '末考'))
go
insert into tablename values('张三','语文','80')
insert into tablename values('张三','数学','58')
insert into tablename values('张三','物理','20')
insert into tablename values('李四','语文','100')
insert into tablename values('李四','物理','未考')
insert into tablename values('李四','英语','76')
insert into tablename values('李四','化学','作弊')select * from tablename
SELECT * FROM tablename
WHERE SCORE='未考' or convert(int,case when ascii(SCORE)<100 then score else '100' end) <60
/*name subject score
---------- ---------- ----------
张三 数学 58
张三 物理 20
李四 物理 未考(所影响的行数为 3 行)
*/
SELECT * FROM tablename
WHERE SCORE='未考' or SCORE='作弊' or convert(int,case when ascii(SCORE)<100 then score else '100' end) <60
/*
name subject score
---------- ---------- ----------
张三 数学 58
张三 物理 20
李四 物理 未考
李四 化学 作弊
*/
convert(int,case when ascii(SCORE)<100 then score else '100' end) <60
insert into tablename values('张三','数学','58')
insert into tablename values('张三','物理','20')
insert into tablename values('李四','语文','100')
insert into tablename values('李四','物理','未考')
insert into tablename values('李四','英语','76')
insert into tablename values('李四','化学','作弊')
select * from tablename where left('000',3-len(score))+ score<'060' or score in('作弊','未考')
drop table tablename
/*
name subject score
---------- ---------- ----------
张三 数学 58
张三 物理 20
李四 物理 未考
李四 化学 作弊
*/
---------- ---------- ----------
111 gs 未考
111 ghf 70
111 gf 41.
111 hr 作弊
222 jhh 48.00
222 gr 80
222 sd 未考
222 uh 作弊
444 fg 生孩子
333 dsa 结婚
333 gt 请假
333 kj 免考
444 jy 不想考
555 JY 59
555 FD 60
555 DV 100
我建了一张模拟表
以下是SOL语句
NAME OBJECT SCORE
---------- ---------- ----------
111 gf 41.
111 gs 未考
111 hr 作弊
222 jhh 48.00
222 sd 未考
222 uh 作弊
555 JY 597 rows selected
这是运行结果
(select * from cjb where SCORE <>'结婚' and score<>'免考' and score<>'生孩子' and score<>'不想考' and score<>'请假' and score<>'作弊'and score<>'未考') CJB01
WHERE SCORE <60
UNION
select * from cjb where score = '未考' or score = '作弊';