Thank you for your answer but unfortunately I tried it and it makes the same kind of ouptut as mine, with multtiple new (false) lines (splitting my initial 79 lines into 2054). I just have a new column with the phylum name but no logic between the phylum and the order, like in the first command (for example, primates are present in the cyanobacteria) Here is the modified command :
SELECT
m.acc,
tax.tax_id,
tax.self_count,
tax.total_count,
tax.total_count * m.avgspotlen AS pb,
tax.total_count * m.avgspotlen / (m.mbases * 1000000) * 100 AS percentage,
class_tax.name AS phylum_name,
tax.name AS order_name
FROM
`nih-sra-datastore.sra.metadata` AS m
JOIN
`nih-sra-datastore.sra_tax_analysis_tool.tax_analysis` AS tax
ON m.acc = tax.acc
LEFT JOIN
(SELECT name, acc FROM `nih-sra-datastore.sra_tax_analysis_tool.tax_analysis` WHERE rank = 'phylum') AS class_tax
ON m.acc = class_tax.acc
WHERE
m.acc = 'DRR000836'
AND m.librarysource = 'METAGENOMIC'
AND (tax.rank = 'order' OR tax.ilevel = 1)
AND assay_type = 'WGS'
AND class_tax.name ="Cyanobacteria"
ORDER BY
pb DESC;
will give:
Line acc tax_id self_count total_count pb percentage phylum_name order_name
16 DRR000836 9443 0 429 222651 0.033837537993920974 Cyanobacteria Primates
17 DRR000836 204455 0 325 168675 0.02563449848024316 Cyanobacteria Rhodobacterales