creating a table and inserting data
/** Grocery list:
Bananas (4)
Peanut Butter (1)
Dark Chocolate Bars (2)
**/ CREATE TABLE groceries (id INTEGER PRIMARY KEY, name TEXT, quantity INTEGER ); INSERT INTO groceries VALUES (1, "Bananas", 4);
INSERT INTO groceries VALUES (2, "Peanut Butter", 1);
INSERT INTO groceries VALUES (3, "Dark chocolate bars", 2);
SELECT * FROM groceries;
This database contains an incomplete list of box office hits and their release year. In this challenge, you're going to get the results back out of the database in different ways! In this first step, just select all the movies.
Now, add a second query after the first, that retrieves only the movies that were released in the year 2000 or later, not before. Sort the results so that the earlier movies are listed first. You should have 2 SELECT statements after this step.
CREATE TABLE movies (id INTEGER PRIMARY KEY, name TEXT, release_year INTEGER);
INSERT INTO movies VALUES (1, "Avatar", 2009);
INSERT INTO movies VALUES (2, "Titanic", 1997);
INSERT INTO movies VALUES (3, "Star Wars: Episode IV - A New Hope", 1977);
INSERT INTO movies VALUES (4, "Shrek 2", 2004);
INSERT INTO movies VALUES (5, "The Lion King", 1994);
INSERT INTO movies VALUES (6, "Disney's Up", 2009); SELECT * FROM movies; SELECT * FROM movies WHERE release_year >= 2000 ORDER BY release_year;
The default sequence is ASC(ascending)order, so from small at the top to large at the bottom.
Aggregating date
CREATE TABLE groceries (id INTEGER PRIMARY KEY, name TEXT, quantity INTEGER, aisle INTEGER);
INSERT INTO groceries VALUES (1, "Bananas", 56, 7);
INSERT INTO groceries VALUES(2, "Peanut Butter", 1, 2);
INSERT INTO groceries VALUES(3, "Dark Chocolate Bars", 2, 2);
INSERT INTO groceries VALUES(4, "Ice cream", 1, 12);
INSERT INTO groceries VALUES(5, "Cherries", 6, 2);
INSERT INTO groceries VALUES(6, "Chocolate syrup", 1, 4); SELECT aisle, SUM(quantity) FROM groceries GROUP BY aisle;
GROUP BY表示从aisle挑选出元素进行汇总
More complex queries with AND/OR
CREATE TABLE exercise_logs
(id INTEGER PRIMARY KEY AUTOINCREMENT, /*id 序号自动增加*/
type TEXT,
minutes INTEGER,
calories INTEGER,
heart_rate INTEGER); INSERT INTO exercise_logs(type, minutes, calories, heart_rate) VALUES ("biking", 30, 100, 110); /*重新声明,只填需要填充的元素名称*/
INSERT INTO exercise_logs(type, minutes, calories, heart_rate) VALUES ("biking", 10, 30, 105);
INSERT INTO exercise_logs(type, minutes, calories, heart_rate) VALUES ("dancing", 15, 200, 120); SELECT * FROM exercise_logs WHERE calories > 50 ORDER BY calories; /* AND */
SELECT * FROM exercise_logs WHERE calories > 50 AND minutes < 30; /* OR */
SELECT * FROM exercise_logs WHERE calories > 50 OR heart_rate > 100;
creating a table and inserting data的更多相关文章
- Creating a Table View Programmatically
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TableView_iPhone/Cre ...
- [Hive - Tutorial] Querying and Inserting Data 查询和插入数据
Querying and Inserting Data Simple Query Partition Based Query Joins Aggregations Multi Table/File I ...
- How To determine DDIC Check Table, Domain and Get Table Field Text Data For Value?
How To determineDDIC Check Table, Domain and Get Table Field Text Data For Value? 1.Get Table Fie ...
- MySQL Data Directory -- Creating file-per-table tablespaces outside the data directory
Creating file-per-table tablespaces outside the data directory 一. Data Directory 1.应对情况 当数据库所在空间不足的时 ...
- MySQL Crash Course #10# Chapter 19. Inserting Data
INDEX BAD EXAMPLE Improving Overall Performance Inserting Multiple Rows INSTEAD OF Inserting a Singl ...
- Creating HTML table with vertically oriented text as table header 表头文字方向
AS an old question, this is more like info or reminder about vertical margin or padding in % that ta ...
- dashDB - Creating a table with CLOB column type
In order to create a table with clob column type, the table has to be created with "ORGANIZE BY ...
- Creating External Table - KUP-04020
原因:因为操作系统环境不同,所以换行符也不同,要查看数据文件的换行符 解决方法: 1.如果是苹果系统类的数据文件,则改为:RECORDS DELIMITED BY 0X'0D' 2.如果是window ...
- ASP.Net MVC – What are the uses of Display, DisplayName, DisplayFormat and ScaffoldColumn attributes
http://www.codeproject.com/Articles/775220/ASP-Net-MVC-What-are-the-uses-of-Display-DisplayNa?utm_so ...
随机推荐
- 使用docker-compose配置mysql数据库并且初始化用户
使用docker-compose配置mysql数据库并且初始化用户 docker-compose 测试创建一个docker-compose.yml测试 以下配置了外部数据卷.外部配置文件.外部初始化 ...
- SSRF攻击原理
目录 什么是SSRF 原理 防护 什么是SSRF 一个对外的Web接口,改接口能让用户控制curl命令,去访问别的web服务. 简图如下 想象一下当用户请求的baidu.com/x.php?image ...
- 学习笔记 - 快速傅里叶变换 / 大数A * B的另一种解法
转: 学习笔记 - 快速傅里叶变换 / 大数A * B的另一种解法 文章目录 前言 ~~Fast Fast TLE~~ 一.FFT是什么? 二.FFT可以干什么? 1.多项式乘法 2.大数乘法 三.F ...
- Java 虚拟机详解
深入理解JVM 1 Java技术与Java虚拟机 说起Java,人们首先想到的是Java编程语言,然而事实上,Java是一种技术,它由四方面组成: Java编程语言.Java类文件格式.Java虚 ...
- 鹅厂二面,nginx回忆录
前天二面鹅厂,面试官问出了"nginx你了解吗?"这样宽泛直白的句式,我一时抓不到重点,一时语噻. 下班想了一下,平时潜移默化用到不少nginx的能力,但在面试的时候没有吹成对应的 ...
- MyBatis架构分析
我们都知道Mybatis是一个非常小巧灵活的ORM框架,深受国内广大开发者的喜爱,我们知道它的出现某种程度是为了消除所有的JDBC代码和参数的手工设置以及结果集的封装问题:基于这个一点,我们就可以 ...
- .NetCore 导出Execl
/* Nuget - NPOI.2.5.1 */ using NPOI.HSSF.UserModel;using NPOI.SS.UserModel;using NPOI.XSSF.UserMode ...
- frida hook_RegisterNatives--使用frida打印so中动态注册的函数
原文地址:https://github.com/lasting-yang/frida_hook_libartfrida -U --no-pause -f package_name -l hook_Re ...
- PTA 求链表的倒数第m个元素
6-7 求链表的倒数第m个元素 (20 分) 请设计时间和空间上都尽可能高效的算法,在不改变链表的前提下,求链式存储的线性表的倒数第m(>)个元素. 函数接口定义: ElementType ...
- c++一些概念
面向对象语言三大特征: 封装,多态,继承 封装: 1.将函数定义到结构体内部,就是封装. 2.编译器会自动传递结构体的指针给函数. 类: 带有函数的结构体,称为类. 成员函数: 结构体里面的函数,称为 ...