转置查询输出 [英] Transpose Query Output

查看:78
本文介绍了转置查询输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


在almsot 2 - 3年后回到Bytes感觉真好..反正这里是我的问题。我想转置我的查询输出。


这里有详细信息..


***表

GDCA

gdcid,gdcid,gdaid,年龄


GDA

gdaid ,名称


***查询


SELECT

gda.id,年龄

来自

gdca

JOIN gda ON(gda.id = gdca.gdaid)

WHERE gdca。 gdcid IN(3573,184)

订购gdca.id


***输出


" ID" 年龄

" 1" 0

" 1" 11

" 2" 0

" 2" 30

" 3" 0

" 3" 1

" 4" " 0"

" 4" 1

" 5" 0

" 5" 1


***我想要它类似


1 2 3 4 5

0 0 0 0 0

11 30 0 0 0

我尝试使用IF()子句甚至是CONCAT然后再使用SUBSTRING_INDEX,但是没有得到所需的输出。


任何指针都表示赞赏。


谢谢和问候,

RP

Hi All,

It feels so good to be back on Bytes after almsot 2-3 years.. anyways here is my quesion. I would like to transpose my query output.

here are the details..


*** Tables
GDCA
gdcid,gdcid,gdaid,age


GDA
gdaid,name


*** Queries

SELECT
gda.id,age
FROM
gdca
JOIN gda ON (gda.id = gdca.gdaid)
WHERE gdca.gdcid IN(3573,184)
ORDER BY gdca.id

*** Output

"id" "age"
"1" "0"
"1" "11"
"2" "0"
"2" "30"
"3" "0"
"3" "1"
"4" "0"
"4" "1"
"5" "0"
"5" "1"

*** I want it something like

1 2 3 4 5
0 0 0 0 0
11 30 0 0 0

I tried using IF() clause or even CONCAT and then SUBSTRING_INDEX, however not getting the required output.

Any pointer is appreciated.

Thanks and Regards,
RP

推荐答案

上面的任何建议..我需要完成一份报告吗?
Any suggestions for above.. i need to complete one report?


我不知道你在做什么。我不知道你是如何从样本数据中得到你的结果的。
I have no idea what you''re trying to do. I don''t see how you get to your results from your sample data.


好的..让我解释一下......


我想输出并不是很难理解..现在我的要求是将列更改成行..


现在查询输出是


id" 年龄

" 1" 0

" 1" 11

" 2" 0

" 2" 30

" 3" 0

" 3" 1

" 4" " 0"

" 4" 1

" 5" 0

" 5" 1


两列一个用于ID,另一列用于AGE ..现在我的要求是这样的......

ID 1 2 3 4 5

年龄0 0 0 0 0

年龄11 30 0 0 0


正常输出如果你看到那里每个ID都有两行。例如ID 1有两个值0和11.在我的要求中,ID应该是列,相关的AGE应该是行,因此对于ID 1,将有两行,一行包含值0,另一行11
@Rabbit


感谢您的回复..我认为现在的要求应该是明确的..


此致,

RP
Okay.. let me explain a bit more..

I suppose output is not much difficult to understand.. now my requirement is to change column into rows..

right now query output is

id" "age"
"1" "0"
"1" "11"
"2" "0"
"2" "30"
"3" "0"
"3" "1"
"4" "0"
"4" "1"
"5" "0"
"5" "1"

Two columns one is for ID and another is for AGE.. now my requirement is something like this...
ID 1 2 3 4 5
AGE 0 0 0 0 0
AGE 11 30 0 0 0

In normal output if you see there are two rows for each ID. e.g. ID 1 has two values 0 and 11. In my requirement ID(s) should be column and related AGE should be rows, hence for ID 1 there would be two rows one containing value 0 and the other 11

@Rabbit

Thanks for the reply.. I think now the requirement should be clear..

Regards,
RP


这篇关于转置查询输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆