上节我们采用SELECT
直接进行列信息提取,实际上可以在提取的同时创建与命名新的列。
以一个例子说明:
sqlite> SELECT lower(trait) AS trait,
...> "chr" || chrom || ":" || position AS region
...> FROM gwascat LIMIT 5;
trait region
-------------------- --------------
asthma and hay fever chr6:32658824
asthma and hay fever chr4:38798089
asthma and hay fever chr5:111131801
asthma and hay fever chr2:102350089
asthma and hay fever chr17:39966427
其中第一句将trait列转为小写并命名为相同的名字trait;第二列通过||
串连字符,创建“chr6:32658824”格式的输出并命名为region。
当某列信息存在NULL
时,可以转为NA
值,方便下游工具(如R
)分析:
sqlite> SELECT ifnull(chrom, "NA") AS chrom , ifnull(position, "NA") AS position, strongest_risk_snp FROM gwascat WHERE strongest_risk_snp == "rs429358";
chrom position strongest_risk_snp
----- -------- ------------------
19 44908684 rs429358
19 44908684 rs429358
NA NA rs429358
以上内容仅是皮毛作为例子,其它常用的SQLite函数包括: