📂
CS-NoteBook
  • Introduction
  • CS144
    • concise introduction to Internet
      • 1.1 Networked Applications
      • 1.2 The 4 Layer Internet
      • 1.3 IP
      • 1.4 A Day in the Life of a Packet
      • 1.5 Principle: Packet Switching
      • 1.6 Principle:Layering
      • 1.7 Principle: Encapsulation
      • 1.8 Byte order and packet formats
      • 1.9 name and addresses:IPv4
      • 1.10 Longest Prefix Match for Link Layer
      • 1.11 Address Resolution Protocol(ARP)
      • 1.12 Summary
    • Transport Layer
      • 2.1 The TCP Service Model
      • 2.2 UDP service model
      • 2.3 ICMP(Internet Control Message Protocol 互联网报文控制协议)
      • 2.4 The End-to-End Principle
      • 2.5 Error Detection:3 schemes (Checksum,CRC and MAC)
      • 2.6 Finite State Machines(有限状态机)
      • 2.7 Flow Control
      • 2.8 Sliding window
      • 2.9 Retransmission Strategies
      • 2.10 TCP Header
      • 2.11 TCP Setup and Teardown
      • 2.12 Recap
    • Package Switching
      • 3.1 The history of Internet
      • 3.2 What is packet switching
      • [3.3 End-to-end delay and Queueing delay
      • 3.4 Playback Buffer(回放缓存区)
  • CS 61C
    • 1.4 C Memory Mangement, Usage
    • 1.5 Intro to Assembly Language, MIPS Intro
    • 1.5 extra bits operation
  • CS 61B
  • CS 61A
    • Function
    • Names
    • The Art of the Function
    • Control
    • Higher-Order Function
    • Recursive Function
    • List
    • Non-Local Assignment
    • Iterators
    • Objects
    • Data Abstraction
    • OOP
    • Inheritance
    • Representations
    • Decomposition
    • Scheme
    • Exceptions
    • Calculator
    • Interpreters
    • Declarative_Programming
    • Table
    • Aggregation
      • More_recursion
    • Databases
    • Distributed_Data
    • Tail Recursion
    • Exercises
      • lab00
      • lab01
      • hw01
      • tree Recursion example -- give Change
  • The Web DevelopMent Bootcamp
    • html5
    • css
    • bootstrap3
    • bootstrap4
    • javascript expression
    • javascript function
Powered by GitBook
On this page
  • SQL
  • select
  • Projecting Tables(投影表)
  • Arithmetic(算术)

Was this helpful?

  1. CS 61A

Declarative_Programming

  • 声明式语言

    • "程序"是对预期结果的描述

    • interpreter 想出如何产生结果

  • 命令式语言

    • "程序"是对计算过程的描述

    • interpreter 执行 execution/evaluation 规则

      用 Python 描述 SQL

      output_table = []
      for row in FROM(*input_tables):
      if WHERE(row):
          output_table += [SELECT(row)]
      if ORDER_BY:
      output_table = ORDER_BY(output_table)
      if LIMIT:
      output_table = output_table[:LIMIT]

      注意,ORDER BY和LIMIT子句仅在确定了输出表中的所有行之后才应用。

SQL

  • SQL(Structured Query Language 结构化查询语言)

    • select 语句可以从头开始创建一个新表,也可以通过投射表来创建一个新表

    • create table 语句给表起了一个全局名称

  • 还有很多其他语句:analyze, delete, explain, insert, replace, update等。

  • 大多数重要的操作是在 select 语句中的

select

  • select 语句总是包含一个以逗号分隔的列描述列表。

  • 列的描述是一个表达式,后面可选择as和列名

  • select [expression] as [name]

  • 两个选择语句的 union 是一个包含它们两个结果的行的表。

    select "delano" as parent, "herbert" as child union
    select "abraham"         , "barack"           union
    select "abraham"         , "clinton"          union
    select "fillmore"        , "abraham"          union
    select "fillmore"        , "delano"           union
    select "fillmore"        , "grover"           union
    select "eisenhower"      , "fillmore";
  • select 的结果只呈现给用户,不储存

  • create table 语句给结果一个名字

  • create table [name] as [select statement];

    create table parents as
      select "delano" as parent, "herbert" as child union
      select "abraham"         , "barack"           union
      select "abraham"         , "clinton"          union
      select "fillmore"        , "abraham"          union
      select "fillmore"        , "delano"           union
      select "fillmore"        , "grover"           union
      select "eisenhower"      , "fillmore";

Projecting Tables(投影表)

  • select 呈现现有表格

  • 一个 select 语句可以使用 from 子句指定一个输入表

    • select [columns] from [table] where [condition] order by [order]

    • [column] 指的是 select [expression] as [name], [expression] as [name], ... ; 中的 [name]

    • select child from parents where parent = "abraham";

    • select parent from parents where parent > child;

  • 可以使用 where 子句选择输入表中的行的子集。

  • 可以使用一个 order by 子句来声明剩余行的排序。

  • 列的描述决定了每条输入行如何投影到结果行。

Arithmetic(算术)

  • 在 select 表达式中, column 名是 row 值。

  • 算术表达式可以将 row 值和常量相结合

create table lift as
 select 101 as chair, 2 as single, 2 as couple union
 select 102 , 0 , 3 union
 select 103 , 4 , 1;

select chair, single + 2 * couple as total from lift;

char

total

101

6

102

6

103

6

PreviousInterpretersNextTable

Last updated 4 years ago

Was this helpful?