如何使用sqlite选择满足特定条件的表格? [英] How do I select table entires that meet specific conditions using sqlite?

查看:90
本文介绍了如何使用sqlite选择满足特定条件的表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为一个虚构的实验室社会创建了表格。其中一个表称为labbranch,我试图创建一个SQLite查询,选择等于或超过100米的表。



labbranch表有6行:labid,name,address,phone,sizeoflab,totaldeskspace。我只包括三个条目,其中两个超过100米。



谢谢



我尝试过:



SELECT sizeoflab

FROM lab

WHERE sizeoflab = 100 ;



当我尝试这个陈述时,我收到错误

解决方案

确定。我创建了你的表并填充它:

 创建  labbranch 

labid int
name varchar 50 ),
地址 varchar 50 ),
手机 varchar 50 ),
sizeoflab int
totaldeskspace int
);

插入 进入 labbranch 1 ' Lab1'' @ Lab1'' 111' 99 99 ) ;
插入 进入 labbranch 2 ' Lab2',< span class =code-string>' @ Lab2'' 222' 100 100 );
插入 进入 labbranch 3 ' Lab3',< span class =code-string>' @ Lab3'' 333' 101 101 );



请注意,该表有6个(不是行)和3个(条目)

您的要求是

Quote:

选择等于或超过100m的那些

所以我的预期结果基于您的描述是获取Lab2和Lab3的详细信息。



当我运行查询时你已经尝试过我收到一条错误信息:

Quote:

TypeError:无法获取属性'substring未定义或空引用这是因为你没有一个叫表实验室。通过使用正确的表名修复此问题:

  SELECT  sizeoflab 
FROM labbranch
WHERE sizeoflab = 100;



我跑了,我得到一个数字,100,返回。根据我的预期结果,我想要2行而不是1行,并且我目前的结果中没有任何有用的信息。



因此将其更改为

  SELECT  labid,name,sizeoflab  FROM  labbranch 
WHERE sizeoflab > = 100 ;



给出结果:

  labid name sizeoflab  
2 Lab2 100
3 Lab3 101


I have created tables for a fictional lab society. One of the tables is called "labbranch" and I am trying to create an SQLite query that selects the ones that are equal to or over 100m.

The "labbranch" table has 6 rows: labid, name, address, phone, sizeoflab, totaldeskspace. I have only included three entries, two of which are over 100m.

thank you

What I have tried:

SELECT sizeoflab
FROM lab
WHERE sizeoflab=100;

When I tried this statement, I received an error

解决方案

Ok. I created your table and populated it thus:

create table labbranch
(
 labid int, 
 name varchar(50), 
 address varchar(50), 
 phone varchar(50), 
 sizeoflab int, 
 totaldeskspace int
);

insert into labbranch values(1,'Lab1','@Lab1','111', 99, 99);
insert into labbranch values(2,'Lab2','@Lab2','222', 100, 100);
insert into labbranch values(3,'Lab3','@Lab3','333', 101, 101);


Note that the table has 6 columns (not rows) and 3 rows (entries)
Your requirements are

Quote:

selects the ones that are equal to or over 100m

So my expected results based on your description are to get details for Lab2 and Lab3.

When I run the query you have already tried I get an error message:

Quote:

TypeError: Unable to get property 'substring' of undefined or null reference

This is because you do not have a table called lab. Fix that by using the correct table name:

SELECT sizeoflab
 FROM labbranch
 WHERE sizeoflab=100;


When I run that I get a single number, 100, returned. From my expected results I wanted 2 rows not one, and there isn't any useful information in the results I currently have either.

So change it to

SELECT labid, name, sizeoflab FROM labbranch
 WHERE sizeoflab >= 100;


Which gives the results:

labid name sizeoflab
2     Lab2 100
3     Lab3 101


这篇关于如何使用sqlite选择满足特定条件的表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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