一衍菱、 導(dǎo)入hellodb.sql生成數(shù)據(jù)庫(kù)
首先導(dǎo)入hellodb.sql生成數(shù)據(jù)庫(kù)
MariaDB [(none)]> mysql -uroot -pmeng < hellodb_innodb.sql
切換數(shù)據(jù)庫(kù)
MariaDB [(none)]> use hellodb
1涂邀、在students表中,查詢(xún)年齡大于25歲侍芝,且為男性的同學(xué)的名字和年齡
MariaDB [hellodb]> select name 姓名,age 年齡,gender 性別 from students where age >25;
2 研铆、以ClassID為分組依據(jù),顯示每組的平均年齡
MariaDB [hellodb]> select classid,avg(age) from students where classid is not null group by classid;
或者執(zhí)行:
MariaDB [hellodb]> select classid,avg(age) from students group by classid having classid is not null;
3州叠、顯示第2題中平均年齡大于30的分組及平均年齡
MariaDB [hellodb]> select classid,avg(age) from students group by classid having classid is not null and avg(age) > 30;
4棵红、顯示以L開(kāi)頭的名字的同學(xué)的信息
MariaDB [hellodb]> select * from students where name rlike '^l';