1.创建数据库
create database mytest;
2.创建表并填充数据,填充方式有手动填充以及导入数据user,item,action
create table user{
user_id
user_sex
user_birthday
user_terms
}
3.数据说明
表 user: 字段 user_id,user_sex,user_birthday,user_terms
表 item: 字段 item_id,item_cat,item_terms
表 action: 字段 user_id,item_id,creat_at,action
use mytest;
status
展现数据
DESC user;
select * from user limit 3;
排序<排序列和方向>
1.只排一列
select user_birthday from user order by user_birthday;
select user_birthday from user order by user_birthday;
DESC;
2.多列排序,升序ASC是默认的
select * from user order by user_id,user_birthday;
select * from user order by user_id DESC,user_birthday;
select * from user order by user_id ,user_birthday DESC;
select * from user order by user_id DESC,user_birthday DESC;
按照自定义列排序
统计频率
在SQL中,会中表内容的数据,使用分组来查询
select user_sex ,count(*) from user group by user_sex;