由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - sql question
相关主题
Oracle Group and Index questionSQL combine two tables into one table and add a new column
请教一个有关SQL concat的问题新手请教SQL 语法问题- alias 和 join
better solution for cross table query in sql?SQL fast search in a 10 million records table (转载)
Re: Recordset - I stuck! Help!最近很多新ID
mysql maximum columns <=1000?新手如何快速学习数据库
扳机问题求助问个sql的问题吧,搞不出来了. (转载)
这个 Oracle SQL 语句该这么写啊?Need help, about select count(xyz) from ...
很弱的Oracle问题ADO & DAO &SQL...Help...
相关话题的讨论汇总
话题: sql话题: what话题: value话题: ab话题: column
进入Database版参与讨论
1 (共1页)
n*********g
发帖数: 75
1
there are records in Database such as
1 A
2 A
2 B
3 C
4 B
I want to return a recordset that combine the value of
the second column if the value of the first column is the same,
like below
1 A
2 AB
3 C
4 B
how to implement it using sql statement?
aw
发帖数: 127
2
use a self-join.
SELECT T1.lastname + isnull(T2.lastname,'')
FROM MYTABLE T1 LEFT JOIN MYTABLE T2
ON T1.firstname = T2.firstname AND T1.id < T2.id

【在 n*********g 的大作中提到】
: there are records in Database such as
: 1 A
: 2 A
: 2 B
: 3 C
: 4 B
: I want to return a recordset that combine the value of
: the second column if the value of the first column is the same,
: like below
: 1 A

y****i
发帖数: 5690
3
I think this way the solution is not scalable. What if there are records like
You will get
Instead of
n*********g
发帖数: 75
4
doesn't work. the sql script returns:
1 A
2 AB
2 B
3 C
4 B
I don't want the third record....
btw: both columns are char

【在 aw 的大作中提到】
: use a self-join.
: SELECT T1.lastname + isnull(T2.lastname,'')
: FROM MYTABLE T1 LEFT JOIN MYTABLE T2
: ON T1.firstname = T2.firstname AND T1.id < T2.id

n****f
发帖数: 905
5
建议您用程序去实现.
在ORACLE 您可以用PL/SQL 去LOOP 整个表.
您的问题主要是同表中行数据和行数据的关系处理.
总之,我认为写一段小程序比较能简单解决您的问题.

【在 n*********g 的大作中提到】
: doesn't work. the sql script returns:
: 1 A
: 2 AB
: 2 B
: 3 C
: 4 B
: I don't want the third record....
: btw: both columns are char

n*********g
发帖数: 75
6
yeah, I agree it is easy to implement in program.
but it is not my decision, sigh.

【在 n****f 的大作中提到】
: 建议您用程序去实现.
: 在ORACLE 您可以用PL/SQL 去LOOP 整个表.
: 您的问题主要是同表中行数据和行数据的关系处理.
: 总之,我认为写一段小程序比较能简单解决您的问题.

n****f
发帖数: 905
7
OK, Please tell us more about your Table:
1. What DB you are using? Access, SQL or Oracle?
2. What is possible value for ID field? 1,2,3..... What is the MAX value?
3. What is possible value for DATA field? Just A,B and C or have more ?
4. How many record do you have?
5. Why you have to use One SQL statement to do that?
Is it possible let me CALL you?

【在 n*********g 的大作中提到】
: yeah, I agree it is easy to implement in program.
: but it is not my decision, sigh.

aw
发帖数: 127
8
还有个前面有人提到的问题,可不可能有:
2 A
2 B
2 C
。。。的情况?就说有未知个相同ID(不止2个)。

【在 n****f 的大作中提到】
: OK, Please tell us more about your Table:
: 1. What DB you are using? Access, SQL or Oracle?
: 2. What is possible value for ID field? 1,2,3..... What is the MAX value?
: 3. What is possible value for DATA field? Just A,B and C or have more ?
: 4. How many record do you have?
: 5. Why you have to use One SQL statement to do that?
: Is it possible let me CALL you?

1 (共1页)
进入Database版参与讨论
相关主题
ADO & DAO &SQL...Help...mysql maximum columns <=1000?
如何用SQL语句判断一个TABLE是否存在?扳机问题求助
ORACLE+VC产生巨大临时文件这个 Oracle SQL 语句该这么写啊?
这句SQL怎么写?很弱的Oracle问题
Oracle Group and Index questionSQL combine two tables into one table and add a new column
请教一个有关SQL concat的问题新手请教SQL 语法问题- alias 和 join
better solution for cross table query in sql?SQL fast search in a 10 million records table (转载)
Re: Recordset - I stuck! Help!最近很多新ID
相关话题的讨论汇总
话题: sql话题: what话题: value话题: ab话题: column