如何压缩查询数据

时间:2017-02-26 01:11:19

标签: oracle

我目前正在使用以下查询来提取相同样本记录中以4行表示的数据,并希望将其展平为每个样本1个ow。非常感谢您附加查询结果以获取任何帮助。

select s.name as CRF, a.name as Aliquot_Name, a.aliquot_type, au.u_step_yield as Step_Yield, au.u_step_concentration as Step_Concentration, au. u_pooled_plasma_volume as Pooled_Plasma_volume
from aliquot a 
join aliquot_user au on a.aliquot_id = au.aliquot_id 
join sample s on s.sample_id = a.SAMPLE_ID
where a.aliquot_type in ('DNA Extracted', 'Library', 'Target Enrichment', 'DNA Plasma')
order by s.name desc, a.aliquot_type, a.name, au.u_step_yield, au.u_step_concentration, au.u_pooled_plasma_volume;
CRF ALIQUOT_NAME    ALIQUOT_TYPE    STEP_YIELD  STEP_CONCENTRATION  POOLED_PLASMA_VOLUME
CRF007650   PE-0046758  DNA Plasma          10
CRF007650   LCNL-47275  Library 2,178   36  
CRF007650   HCNLS-47467 Target Enrichment   105 2   
CRF007649   1146667362  DNA Extracted   451 6   
CRF007649   PE-0046774  DNA Plasma          10
CRF007649   LCNL-47291  Library 3,543   59  
CRF007649   HCNLS-47483 Target Enrichment   132 2   
CRF007648   1146668498  DNA Extracted   166 2   
CRF007648   PE-0046755  DNA Plasma          9
CRF007648   LCNL-47272  Library 3,881   65  
CRF007648   HCNLS-47463 Target Enrichment   381 6   
CRF007647   1146635220  DNA Extracted   29  0   
CRF007647   PE-0046764  DNA Plasma          8
CRF007647   LCNL-47281  Library 1,274   21  
CRF007647   HCNLS-47473 Target Enrichment   57  1   
CRF007646   1146736347  DNA Extracted   67  1   

2 个答案:

答案 0 :(得分:0)

我认为你必须更具体。 没有桌子的信息。这是pk而不是。 我现在只能说,如果你想要平整行,你必须加入同一个表。 如果您想通过查询获得答案,则必须编写表格信息,其他人可以帮助人们回答您的问题。

答案 1 :(得分:0)

据我了解您的数据,您可以在表格中输入4个不同的a.aliquot_type(' DNA Extracted',' Library',' Target Enrichment&# 39;,' DNA Plasma')。并且你想给4列带有相应的Aliquot_Name(一个用于' DNA Extracted'等)。

您可以使用带有子选择的4列,您可以从等分中读取相应的数据,因此您必须退出连接

a.aliquot_id = au.aliquot_id

例如:

select s.name as CRF, (select a.aliquot_type from aliquot where a.aliquot_type = 'DNA Extracted' and ....) col1,  (select a.aliquot_type from aliquot where a.aliquot_type = 'Library' and ....) col2, ...