Office中国论坛/Access中国论坛

标题: [可能有点难]求助高手:以下的查询怎么做? [打印本页]

作者: sancai888    时间: 2006-5-9 20:20
标题: [可能有点难]求助高手:以下的查询怎么做?
表格式
ID     A       B      C     D
1     11      12     13
2     21      22     23     24
3     31               33


查询结果格式
1     11
       12
       13
2     21
       22
       23
       24
3     31
       33   



谢谢!最好少采用几个查询转换。。。。。。
作者: wwwwa    时间: 2006-5-9 21:54
try:SELECT *
FROM [select id,a from b105q where id=1 union select id,b from b105q where id=1 union

select id,c from b105q where id=1 union select id,d from b105q where id=1

union select id,a from b105q where id=2 union select id,b from b105q where id=2

union select id,c from b105q where id=2 union select id,d from b105q where id=2
union select id,a from b105q where id=3 union select id,b from b105q where id=3

union select id,c from b105q where id=3 union select id,d from b105q where id=3]. AS [%$##@_Alias]
WHERE not isnull(a);


[此贴子已经被作者于2006-5-9 14:02:14编辑过]


作者: LucasLynn    时间: 2006-5-9 23:09
以下是引用sancai888在2006-5-9 12:20:00的发言:


表格式
ID     A       B      C     D
1     11      12     13
2     21      22     23     24
3     31               33


查询结果格式
1     11
       12
       13
2     21
       22
       23
       24
3     31
       33   

谢谢!最好少采用几个查询转换。。。。。。





SELECT id,A as Data FROM tblSample WHERE not isnull(A) UNION ALL
SELECT id,B as Data FROM tblSample WHERE not isnull(B) UNION ALL
SELECT id,C as Data FROM tblSample WHERE not isnull(C) UNION ALL
SELECT id,D as Data FROM tblSample WHERE not isnull(D);


然后根据自己的需要ORDEY BY或者GROUP BY。





[此贴子已经被作者于2006-5-9 15:09:38编辑过]






欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3