1、查询MySQL支持的数据类型 “? data types;”2、查看int的用法“? int”3、查看show的用法“? show”4、查看创建数据库表语句的用法“? create table”版权声明:本文为博主原创文章,未经博主允许不得转载。原文:http://blog.csdn.net/you23hai45/article/details/48499299
在学习时,我在update语句中子查询了修改表,报出如下错误You can‘t specify target table ‘beauty‘ for update in FROM clause原因是不能子查询select出同一表中的某些值,再update这个表(在同一语句中)错误案例 UPDATE beauty SET boyfriend_id =2 WHERE beauty.id IN (SELECT beauty.id id FROM beauty LEFT JOIN boys ON boys.id=beauty.`boyfriend_id`WHERE beauty.`boyfriend_id` IS NULL)应该写法 UPDATE beauty SET b...
-- 查询今天的数据 select * from `user` where to_days(birthday) = to_days(CURDATE()); -- 查询昨天的数据 =1; ' ref='nofollow'>select * from `user` where to_days(CURDATE()) - to_days(birthday)<=1; -- 查询最近7天的数据 (CURDATE(),INTERVAL 7 DAY); ' ref='nofollow'>select * from `user` where birthday > DATE_SUB(CURDATE(),INTERVAL 7 DAY); -- 查询最近一个季度的数据 (CURDATE(), INTERVAL 3 MONTH) ' ref='nof...
use abccCREATE TABLE Account(ID INT(11),name VARCHAR(255),class VARCHAR(255))select * from Account;INSERT INTO account VALUES(1,“小汗”,“高三二班”),(2,“小涛”,“高三一班”),(3,“小浩”,“高三二班”),(4,“小彬”,“高三一班”),(5,“小鱼”,“高三一班”),(6,“小驴”,“高三二班”),(7,“小凯”,“高三一班”)CREATE TABLE Exam(id INT,course VARCHAR(255),Score INT,Aid INT)select * from Exam;INSERT INTO ...
1. 需求:获得0115班所有的代课教师代课天数,结果按照升序排序;同时获得0228班,结果按照降序排序。(1)首先查询原来的0115班和0228班所有代课天数,如下: (2)使用union关键字,如下: (3)修改韩信在php0115班的记录都是days =15,如下: (4)此时我们再去使用union组合查询,就会出现问题,如下: 注意: 如果union的结果存在重复的记录,那么就会消除重复,类似执行了distinct操作。该怎么解决这个问题? ...
简单查询: select * from tb_name select field1,field2 from tb_name; select * from tb_name where qualification ; 例子:select name,age from students where age+1>20; select name from student where age>20 and gender=‘M‘; select name from student where age>20 or gender=‘M‘; select name from student where not age>20 and not gender=‘M‘; select name fr...
1 #!/bin/bash 2 #查询3 echo -e 4 for i in `cat id.txt` 5 do 6 A=`mysql -h10 -uw -p2012 -Ne "select
Id,Name,User_Logindate from info where Id=$i"`; 7 B=`mysql -h10 -uw -p2012
-Ne "select ifnull(sum( Amount),0) from Info where Date between
‘2014-05-21‘ and ‘2014-05-22‘ and Id=$i and Res=1"` 8 echo -e
"$A\t\t\t\t$B\t" >> tmp.xls; 9 done原文:http://www.cnblogs.com/fupeng/p/3752913...
现在有两个表,table1和table2,table1有1千万数据(id 主键索引),table2有三条数据(uid字段 3,5,7);select*from table1 where id in ( select uid from table2 );眨眼一看感觉这条语句应该很快;可能你会一厢情愿的以为 先执行括号里面的语句,然后在执行外层的select;外层的select用上了 id主键速度应该飞起来才对;实际上这条语句执行非常慢,我这里测试20s;通过 explain 分析,这条语句没有用上索引,而是全表扫描;原...
联合查询基本概念联合查询是可合并多个相似的选择查询的结果集。等同于将一个表追加到另一个表,从而实现将两个表的查询组合在一起,使用为此为UNINO或UNION ALL 联合查询:将多个查询的结果合并到一起(纵向合并):字段数不变,多个查询的记录数合并 应用场景1、将同一张表中不同的结果(需要对应多条查询语句来实现),合并到一起展示数据 2、最常见:在数据量大的情况下,会对表进行分表操作,需要对每张表进行部分数据统计,使...
慢查询日志是由一些SQL语句构成的,当查询时间超过了long_query_time的值时会生成慢查询日志,long_query_time的最小值是1s,默认值是10s。检查MySQL慢查询是否开启:[Python] 纯文本查看 复制代码?123456789mysql> show variables like ‘%slow%‘;+---------------------+----------------------------------------------------------+| Variable_name | Value |+----...
查询所有数据库占用磁盘空间大小的SQL语句:select TABLE_SCHEMA, concat(truncate(sum(data_length)/1024/1024,2),‘ MB‘) as data_size,
concat(truncate(sum(index_length)/1024/1024,2),‘MB‘) as index_size
from information_schema.tables
groupby TABLE_SCHEMA
orderby data_length desc; 查询单个库中所有表磁盘占用大小的SQL语句:select TABLE_NAME, concat(truncate(data_length/1024/1024,2),‘ MB‘) as data_size...
1、连接查询select * from Info,Nation #笛卡尔积select * from Info,Nation where Info.Nation=Nation.Codejoin on 连接select * from Info join Nation #join连接select * from Info join Nation on Info.Nation=Nation.Code2、联合查询select Code,Name from Infounionselect Code,Name from Nation3、子查询1)无关子查询select * from Nation where Name=‘汉族‘ #去Nation表中查名族代号select * from Info where Nation=(民...
当需要从数据库查询的表有上万条记录的时候,一次性查询所有结果会变得很慢,特别是随着数据量的增加特别明显,这时需要使用分页查询。对于数据库分页查询,也有很多种方法和优化的点。下面简单说一下我知道的一些方法。准备工作为了对下面列举的一些优化进行测试,下面针对已有的一张表进行说明。表名:order_history描述:某个业务的订单历史表主要字段:unsigned int id,tinyint(4) int type字段情况:该表一共37个字段,不包含...
mysql慢查询日记<pre>#必须写到mysqld 注意给/tmp/showslowmysql.log 775权限 要写入权限[mysqld]#开启慢查询日记slow_query_log = 1#设置日记路径slow_query_log_file = /tmp/showslowmysql.log#超过1秒 就代表慢查询记录到日志long_query_time=1 mysql> show variables like ‘%query%‘;+------------------------------+------------------------+| Variable_name | Value |+---------------...
1. [代码][C/C++]代码 #include <mysql/mysql.h>#include <stdio.h>#include <string.h>int main(){ MYSQL mysql;//连接数据库的变量 MYSQL_RES *res;//存放查询结果的变量 MYSQL_ROW row; char *query; int t,r; char *server= "localhost"; char *user = "root"; char *password="test"; char *database = "test"; mysql_init(&mysql); //连接数据库前,必须调用此函数初始化变量 /** *...