Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL大于查询_Sql_Sqlite - Fatal编程技术网

SQL大于查询

SQL大于查询,sql,sqlite,Sql,Sqlite,我是sqlite的新手,希望大大扩展我的技能。我创建了一个包含两个表的简单数据库,“products”和“shopping” 我使用以下查询创建了我的第一个表和值 sqlite> CREATE TABLE shopping(Product TEXT PRIMARY KEY, Quantity NOT NULL); sqlite> INSERT INTO shopping(Product, Quantity) VALUES ('Jam', 1); sqlite> IN

我是sqlite的新手,希望大大扩展我的技能。我创建了一个包含两个表的简单数据库,“products”和“shopping”

我使用以下查询创建了我的第一个表和值

sqlite> CREATE TABLE shopping(Product TEXT PRIMARY KEY, Quantity       NOT NULL);
sqlite> INSERT INTO shopping(Product, Quantity) VALUES ('Jam', 1);
sqlite> INSERT INTO shopping(Product, Quantity) VALUES ('Bread', 2);
sqlite> INSERT INTO shopping(Product, Quantity) VALUES ('Tea', 5); 
sqlite> INSERT INTO shopping(Product, Quantity) VALUES ('Cereal', 1);
和下面的查询来创建我的第二个表

sqlite> CREATE TABLE ProductData(Product TEXT PRIMARY KEY, Price NOT NULL);
sqlite> .import /home/solidsnake/Documents/ProductData.csv ProductData
此表的值,其中通过.csv文件导入

qlite> SELECT Product, Price
...> FROM products;
给出输出:

Jam,250
Tea,150
Cereal,120
Eggs,170
Cheese,320
Potatoes,80
Treacle,80
Bananas,100
Bread,230
Caviar,1000
Jam,250
Tea,150
Eggs,170
Cheese,320
Potatoes,80
Treacle,80
Bread,230
我现在遇到的主要问题是,我需要使用SQL查询来找出商店中哪些产品的成本高于120

在互联网上彻底搜索之后,我发现为我提供正确输入的正确查询是

SELECT * FROM "products" WHERE Price > '120';
但是,这给了我以下输出:

Jam,250
Tea,150
Cereal,120
Eggs,170
Cheese,320
Potatoes,80
Treacle,80
Bananas,100
Bread,230
Caviar,1000
Jam,250
Tea,150
Eggs,170
Cheese,320
Potatoes,80
Treacle,80
Bread,230
正如你所看到的,土豆和糖浆的价格都是80,低于120。此外,鱼子酱没有在输出中提供,这似乎很奇怪,因为它的价格为1000

有没有人能给我指出正确的方向,我的语法有什么问题,为什么会产生错误的输出

另外,很抱歉这篇冗长的文章,但我想提供尽可能多的信息。我是stackoverflow的新手,我试着尽可能地关注“如何提问”这篇文章

谢谢

编辑:已解决


谢谢你。最后我把购物桌移走了,重新做了一个,并采纳了你的建议。查询现在工作正常。

请不要与字符串值比较(使用整数):

字符串排序不同于整数,因此'80'>'120'是正确的 “1000”和“120”也是正确的

SELECT '80' > '120', 80 > 120
-- 1 0

SELECT '1000' > '120', 1000 > 120
-- 0 1

加上定义数量数据类型:

CREATE TABLE shopping(Product TEXT PRIMARY KEY, Quantity   INT    NOT NULL);

谢谢你的迅速回复。我将其与整数值(而不是字符串)进行了比较,但输出现在显示products表中的所有内容,包括价格低于120的产品。@GeorgeStrawbridge您还需要定义Quantity Datatype再次感谢您的建议。我是否认为我需要完全移除购物桌并重新创建它?或者可以说,它可以在运行中进行编辑吗?