首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

怎样给带distinct的查询结果加上字符串?该怎么处理

2012-02-23 
怎样给带distinct的查询结果加上字符串?我的查询语句是这样的SQL codeselect distinct customer_code from

怎样给带distinct的查询结果加上字符串?
我的查询语句是这样的

SQL code
select distinct customer_code from purchase_customer_balance order by customer_code


我想在查询结果中添加字符串,如下
SQL code
select distinct '@'+customer_code'#' from purchase_customer_balance order by customer_code


但执行错误,提示如下:
如果指定了 SELECT DISTINCT,那么 ORDER BY 子句中的项就必须出现在选择列表中。

怎样解决这个问题?

另外如果我想添加的字符串不是 @ 而是 ' 怎样解决?

[解决办法]
SQL code
select distinct '@'+customer_code+'#' from purchase_customer_balance order by customer_code
[解决办法]
SQL code
select distinct '@'+customer_code + '#' from purchase_customer_balance order by 1or :select distinct '@'+customer_code + '#' from purchase_customer_balance order by '@'+customer_code + '#'
[解决办法]
SQL code
SELECT DISTINCT        '@' + customer_code + '#'FROM    purchase_customer_balanceORDER BY '@' + customer_code + '#'
[解决办法]
select distinct '@'+customer_code'#' from purchase_customer_balance order by '@'+customer_code'#'

热点排行