mysql_控制台基本使用

--  登录这部分

sql> mysql -u sa - p

sql>123 


-- 基本表、数据库的命令使用

sql> show basetables; // 有一个s, 不区分场景

+----------------------------------------+

| Database |

+----------------------------------------+

| information |

| lw_db    |

| mysql |

| scujcc |

+----------------------------------------+


sql> use scujcc;

sql> show tables;

+----------------------------------------+

| t_bank |

...

+----------------------------------------+

sql> describe t_bank;

-- 可以看到表结构

sql> select * from t_bank;

-- 可以看到表里所有的数据


-- 基本操作语句的使用

1.查询

基本的统计表单

select * from

(select count(*), if(sum(amt) = NULL, 0, sum(amt)) sum from t_order_info)  a //一定要有别名

... b


使用嵌套查询而不是left join, 统计交了此项项目的人员

select (select count(*) from t_order_info where feeitem_id = o.feeitem_id and order_status = 1) 

count_person from t_feeitem o // count只能直接作用于数据, 而不能嵌套查询


使用count而不是in或者not in, 统计未支付的人员数量

select (

select count(*) from t_customer_fee_list cust //订单表里的数量非常大, 不能使用in或者not in

where cust.feeitem_id = t.feeitem_id

and (select count(*) from t_order_info

where cust_no = cust.cust_no

and order_status = 1) = 0

) not_pay_num from t_feeitem t;


union 相同主键的数据则融合起来

union all 相同主键的都存在


修改表结构

drop table if exists `t_test_info`;

create table `t_test_info` (

`id` int not null auto_increment comment '编号',

`login_id` varchar(32) not null comment '用户名',

`password` varchar(32) not null comment '密码',

`create_date` date not null default date_format(now(), '%Y-%m-%d' ) comment '创建时间',

`create_time` time not null default date_format(now(), '%H:%i:%s') comment '创建详细时间',

`create_timestamp` datetime not null default date_format(now(), '%Y-%m-%d %H-%i-%s') comment '详细时间',

`remark` varchar(256) not null comment '备注',


primary key (`id`),

unique key (`login_id`) //不能用逗号

) comment '测试表';


alter table `t_order_info` add column `remark` varchar(256) null comment '备注' after `sync_flag`;

alter table `t_order_info` drop column `remark`;


delete from `t_order_info` where id = 1123;

drop table if exists `t_order_info`;

drop database if exists `hello`;

insert, update, delete用于记录, drop用于对象基本类似


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值