zoukankan      html  css  js  c++  java
  • MYSQL语句笔记1

    1.连接数据库.在Juptor中进行SQL操作时,需要加上%sql,%%sql

    %sql mysql://studentuser:studentpw@mysqlserver/dognitiondb
    /*Now that the SQL library is loaded, we need to connect to a 
    database. The following command will log you into the MySQL 
    server at mysqlserver as the user 'studentuser' and will select the 
    database named 'dognitiondb' :
    */

    2.查看数据库中的表格

    /*. To determine how many tables each database has, use the SHOW command:
    */
    
    %sql SHOW tables 
    SHOW columns FROM (enter table name here)
    
    /*or if you have multiple databases loaded**/
    SHOW columns FROM (enter table name here) FROM (enter database name here)
    
    /*or*/
    SHOW columns FROM databasename.tablename

    或者用DESCRIBE函数代替。

    /*DESCRIBE tablename*/
    
    %sql DESCRIBE reviews

    3.SELECT语法

    /*Using SELECT to look at your raw data*/
    /*
    SELECT is used anytime you want to retrieve data from a table. In order to retrieve that data, you always have to provide at least two pieces of information:
    (1) what you want to select, and      
    (2) from where you want to select it.  
    Table or column names with spaces in them need to be surrounded by quotation marks in SQL. MySQL accepts both double and single quotation marks,
    but some database systems only accept single quotation marks.
    In all database systems, if a table or column name contains an SQL keyword, the name must be enclosed in backticks instead of quotation marks.
    */ %%sql SELECT breed FROM dogs;

    4.LIMIT

    /*
    In the next cell, try entering a query that will let you see the first 10 rows of the breed column in the dogs table.
    */
    
    %%sql 
    SELECT breed
    FROM dogs LIMIT 10

    5.OFFSET

    SELECT breed
    FROM dogs LIMIT 10 OFFSET 5;
    /*10 rows of data will be returned, starting at Row 6.
    or */
    SELECT breed
    FROM dogs LIMIT 5, 10;

    6.稍微复杂点的

    /*从表中选择多列
    */
    SELECT breed, breed_type, breed_group
    FROM dogs LIMIT 5, 10;
    /*return all the data in a table.(wild card)*/
    SELECT *
    FROM dogs LIMIT 5, 10;

    算术操作。

    /*
    SELECT statements can also be used to make new derivations of individual columns using "+" for addition, "-" for subtraction, "*" for multiplication, or "/" for division. For example, if you wanted the median inter-test intervals in hours instead of minutes or days, you could query:
    */
    SELECT median_iti_minutes / 60
    FROM dogs LIMIT 5, 10;
    The Safest Way to Get what you Want is to Try and Deserve What you Want.
  • 相关阅读:
    Windows Phone 7 电话本相关的操作
    Windows CE 下判断 URL 地址是否有效
    cigarettes
    开灯问题
    日期计算
    小学生算术
    另一种阶乘问题
    鸡兔同笼
    笨小熊
    6174问题
  • 原文地址:https://www.cnblogs.com/Shinered/p/9501070.html
Copyright © 2011-2022 走看看