MySQL Flashcards
从user表查询score为100并且country为China的username,password
从user表查询score为100或者country为China的username,password
select username,password from user where score=100 and country=’China;
select username,password from user where score=100 or country=’China;
说说having的作用和用法
having用作筛选
SELECT cust_id, COUNT() AS orders FROM orders GROUP BY cust_id HAVING COUNT() > 2
where在分组前过滤,having在分组后过滤
查看所有数据库
show databases;
创建一个名为MYSQLDATA的数据库
create database MYSQLDATA;
从products表中查询price的平均值 从products表中查询price的最大值 从products表中查询price的最小值 从products表中查询price的综合 查询price共有多少行(空也算) 查询price共有多少行(空的不算)
select avg(price) as avgprice from products; select max(price) as avgprice from products; select min(price) as avgprice from products; select sum(price) as avgprice from products; select count(*) from products;空的也算 select count(price) from products;空的不算
在user表中插入一条数据:
username:hijack
passwd:123456
在user表中插入6条数据: username:hijack1 passwd:1 username:hijack2 passwd:2 username:hijack3 passwd:3 username:hijack4 passwd:4 username:hijack5 passwd:5 username:hijack6 passwd:6
insert into user (username,passwd) values (‘hijack’,’123456’);
insert into user (username,passwd) values (‘hijack1’,’1’), (‘hijack2’,’2’), (‘hijack3’,’3’), (‘hijack4’,’4’), (‘hijack5’,’5’), (‘hijack6’,’6’);
从user表中检索name,password列,按照列id降序排列
select name,password from user order by id desc;
从score这个表中检索class列
select class from score;
union干什么用的
用于合并两个或多个select语句的结果集,并消除重复行 如果要保留重复行,用union all select column_name from table1 union select column_name from table2
从user表中查询id=8的username,passwd
从user表中查询score不等于100的username,passwd
select username,passwd from user where id=8;
select username,passwd from score where score <>100;
从user表中查询username和passwd,结果用username—-passwd形式表示
select concat(username,’—-‘,passwd) from user
切换数据库:MYSQLDATA
use MYSQLDATA;
登陆mysql
用户名:hijack
主机名:myserver
端口:9999
mysql -u hijack -p -h myserver -P 9999
从score这个表中检索所有列
select * from score;
select子句的顺序是什么
select from where group by having order by limit