从sqlite中的表中获取数据 [英] Get data from table in sqlite

查看:340
本文介绍了从sqlite中的表中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库test.db,在这个db文件中有两个表存在info1和info2。



info1 data

id |姓名|性别

----------------

1 | A |男性

2 | B |男性

3 | C |女性

4 | D |男性



info2 |数据

-----------

id |标记

1 | 90

3 | 85





所以,现在我想要得到的结果如下,

比较| id |名字|性别

--------------------------

true | 1 | A |男性

false | 2 | B |男性

true | 3 | C |女性

false | 4 | D |男性





如何为此写查询?

I have one database test.db, in this db file two tables are present info1 and info2.

info1 data
id |name |gender
----------------
1 |A |male
2 |B |male
3 |C |female
4 |D |male

info2| data
-----------
id | marks
1 | 90
3 | 85


So, now I want get result like,
compare | id | name | gender
--------------------------
true | 1 | A | male
false | 2 | B | male
true | 3 | C | female
false | 4 | D | male


How to write query for this?

推荐答案

考虑info1是您要比较并希望得到结果的邮件表。



Considering info1 is your mail table to which you are comparing and wants the result.

Select case when i2.id is null then 'false' else true end as 'compare',
i1.id,i1.name,i1.gender
from info1 i1 left outer join info2 i2
on i1.id = i2.id


这篇关于从sqlite中的表中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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