何炅左旋咖啡官网:SQL查询结果中更改字段值
来源:百度文库 编辑:杭州交通信息网 时间:2024/05/19 23:20:44
假如我有一个表 Goods
---------------------------------
id name
1 apple
2 apple
3 peach
4 banana
5 pear
6 orange
7 banana
8 apple
---------------------------------
现在我把重复的数据找出来,我不要删掉重复的
select * from goods where name in (select name where goods group by name having count(name)>1) order by name
找出来的结果是
---------------------------------
id name
1 apple
2 apple
8 apple
4 banana
7 banana
---------------------------------
我现在要想在找出来的名字后来加上它所在的组里的序号以区分开
---------------------------------
id name
1 apple1
2 apple2
8 apple3
4 banana1
7 banana2
---------------------------------
请问这个代码应该怎么写呢?
再执行select * from goods时,出现的结果就是
---------------------------------
id name
1 apple1
2 apple2
3 peach
4 banana1
5 pear
6 orange
7 banana2
8 apple3
---------------------------------
请下面回答问题的朋友注意一下,我的目的不是用select查询,而是更新。
---------------------------------
id name
1 apple
2 apple
3 peach
4 banana
5 pear
6 orange
7 banana
8 apple
---------------------------------
现在我把重复的数据找出来,我不要删掉重复的
select * from goods where name in (select name where goods group by name having count(name)>1) order by name
找出来的结果是
---------------------------------
id name
1 apple
2 apple
8 apple
4 banana
7 banana
---------------------------------
我现在要想在找出来的名字后来加上它所在的组里的序号以区分开
---------------------------------
id name
1 apple1
2 apple2
8 apple3
4 banana1
7 banana2
---------------------------------
请问这个代码应该怎么写呢?
再执行select * from goods时,出现的结果就是
---------------------------------
id name
1 apple1
2 apple2
3 peach
4 banana1
5 pear
6 orange
7 banana2
8 apple3
---------------------------------
请下面回答问题的朋友注意一下,我的目的不是用select查询,而是更新。
应该将序号转成字符串型才能连上的:
select id, name+cast(序号 as varchar) from goods where name in (select name where goods group by name having count(name)>1) order by name
select id, name+序号 from goods where name in (select name where goods group by name having count(name)>1) order by name
SQL查询结果中更改字段值
SQL server2000中,怎么样使得在查询结果中增加一个字段,该字段显示查询结果的行号
SQL server2000中怎么样使得在查询结果中增加一个字段,该字段显示查询结果的行号
用SQL查询语句查询多个表时,如何在结果中加入序号(字段)?
难题 sql 中 null 字段 查询
SQL查询 同字段多结果的简洁写法
asp中用sql语句联合查询多个表,如果两个表中有相同字段,查询结果会怎样?
要查询 Ciass 表中字段c_stu 值 大于50,或者小于20的记录,并只返回c_name和c_stu字段,应该如何写SQL语句?
请问,asp中查询access时,如何在查询结果中合并两个字段
sql结果查询