好吧,我有四个桌子,我需要联合前两个,然后与另外两个桌子进行另一个联盟的内部联接,我被卡住了,谢谢
SELECT miRNA, Gene_Symbol FROM
(SELECT cons.miRNA, cons.Gene_Symbol
FROM conserved_site_context_scores cons
WHERE cons.miRNA = 'hsa-miR-29c'
UNION
SELECT noncons.miRNA , noncons.Gene_Symbol
FROM nonconserved_site_context_scores noncons
WHERE noncons.miRNA = 'hsa-miR-29c'
) AS targetScan
SELECT mirna_name, gene_symbol FROM (
SELECT sc.mirna_name, sc.gene_symbol
FROM hg19_predictions_s_c_aug2010 sc
WHERE sc.mirna_name = 'hsa-miR-29c'
UNION
SELECT oc.mirna_name, oc.gene_symbol
FROM hg19_predictions_0_c_aug2010 oc
WHERE oc.mirna_name ='hsa-miR-29c'
) AS microRNA
INNER JOIN microRNA
ON targetScan.miRNA = microRNA.mirna_name
WHERE targetScan.miRNA = 'hsa-miR-29c';
答案 0 :(得分:1)
我猜你在试图找出JOIN
上面两个UNION
语句的方法?如果是这样,试一试:
SELECT miRNA, Gene_Symbol
FROM
(
SELECT cons.miRNA, cons.Gene_Symbol
FROM conserved_site_context_scores cons
WHERE cons.miRNA = 'hsa-miR-29c'
UNION
SELECT noncons.miRNA , noncons.Gene_Symbol
FROM nonconserved_site_context_scores noncons
WHERE noncons.miRNA = 'hsa-miR-29c'
) AS targetScan INNER JOIN
(
SELECT mirna_name, gene_symbol
FROM (
SELECT sc.mirna_name, sc.gene_symbol
FROM hg19_predictions_s_c_aug2010 sc
WHERE sc.mirna_name = 'hsa-miR-29c'
UNION
SELECT oc.mirna_name, oc.gene_symbol
FROM hg19_predictions_0_c_aug2010 oc
WHERE oc.mirna_name ='hsa-miR-29c'
) AS microRNA
ON targetScan.miRNA = microRNA.mirna_name
WHERE targetScan.miRNA = 'hsa-miR-29c';
我认为您不需要最后的WHERE
条件,因为它已经包含在UNION
中。
答案 1 :(得分:1)
试试这个:
SELECT miRNA, Gene_Symbol
FROM (
SELECT cons.miRNA, cons.Gene_Symbol
FROM conserved_site_context_scores cons
WHERE cons.miRNA = 'hsa-miR-29c'
UNION
SELECT noncons.miRNA, noncons.Gene_Symbol
FROM nonconserved_site_context_scores noncons
WHERE noncons.miRNA = 'hsa-miR-29c'
) AS targetScan
Inner Join
(
SELECT mirna_name, gene_symbol
FROM (
SELECT sc.mirna_name, sc.gene_symbol
FROM hg19_predictions_s_c_aug2010 sc
WHERE sc.mirna_name = 'hsa-miR-29c'
UNION
SELECT oc.mirna_name, oc.gene_symbol
FROM hg19_predictions_0_c_aug2010 oc
WHERE oc.mirna_name = 'hsa-miR-29c'
)tbl
)AS microRNA
ON targetScan.miRNA = microRNA.mirna_name
WHERE targetScan.miRNA = 'hsa-miR-29c';