数据库一列中只有1,2(1代表张三2代表李四)用SQL语句怎么实现输出是张三或李四,而不是1和2?

2025-03-23 12:37:30
推荐回答(5个)
回答1:

假设有一表为 table4 字段有userid 表内容如下
表名 table4
userid
1
2
如果用SQL语句实现输出1是张三 2是李四 可参考一下SQL语句

select(case table4.userid when 1 then '张三' when 2 then '李四' end) as 'userid' from table4

即可实现!请尝试操作!

回答2:

<%sql="select * from tablename "
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
if not rs.bof then
do while not rs.eof
if rs("1对应的字段")=1 then
response.write "张三"
elseif rs("2对应的字段")=2 then
response.write "张三"
end if
rs.close
set rs=nothing
%>

回答3:

select 1 张三,2 李四 from table;
就是 属性+空格+你的命名

回答4:

SELECT RYMC=CASE [列名] when 1 then '张三' when 2 then '李四' else '' END
FROM [表名]

回答5:

SELECT CASE 列名 when 1 then '张三' when 2 then '李四'
FROM 表名