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.
  • 相关阅读:
    一个简单的Python字符串处理文件
    hexo + Github 搭建问题综述
    node scripts/install.js 停顿解决办法
    Mac下安装hexo Error: Cannot find module './build/Release/DTraceProviderBindings 解决
    Python学习札记(三十八) 面向对象编程 Object Oriented Program 9
    Python学习札记(三十七) 面向对象编程 Object Oriented Program 8 @property
    比较两个目录的文件是否相同
    python Polygon模块安装
    ls操作总结
    导入其他python文件或者python文件的函数
  • 原文地址:https://www.cnblogs.com/Shinered/p/9501070.html
Copyright © 2011-2022 走看看