测试人社区

【问题求助】用sql语句更新数学,语文成绩小于等于80分的学生成绩为80分

image

updare 表名 set Score=80 where Score <= 80

好像不对,需要筛选数学和语文字段

那在后面加上个and语句筛选就行了

updare 表名 set Score=80 where Score <= 80 and nameclass like ‘%语文%’

updare 表名 set Score=80 where Score <= 80 and nameclass like ‘%语文%’ or nameclass like ‘%数学%’

是和的关系不是或的关系 :grin:

UPDATE stutab s set s.sscore=‘80’ WHERE EXISTS
(SELECT t1.sid from stutab t1 WHERE t1.sclass = ‘数学’ and t1.sscore <=‘80’
UNION ALL
SELECT t2.sid from stutab t2 WHERE t2.sclass = ‘语文’ and t2.sscore <=‘80’)