bitscn.com
mysql那些事儿之(四)数据表数据查询操作 select 语句 select select_list1,... --要查询哪些列from select_table --从哪一张表里查where primary_constraint --查寻的行满足哪些条件group by grouping_columns --怎样对结果进行分组having secondary_constraint --行必须满足的第二条件order by sorting_columns --怎样对结果进行排序limit count --结果限定 1.普通查询 命令:select * from tbname; 功能:从表tbname中查出所有列的数据。 2.查询特定的行 命令:select * from tbname where colname='值'; 功能:从表中tbname中查出列值等于 ‘值’的行。 3.查询特定的列 命令:select col1,col2 from tbname; 功能:从表中查询出col1,col2两列。 4.查询排序 命令:order by column_name [asc|desc][,...] 功能:使用oeder by子句对查询出来的结果 按一列或多列进行排序,其中asc为按升序排序,为默认值;desc为降序。order by不能按text和image进行排序。 5.查询分组 命令:group by col_name... 功能:根据所给的列名进行分组 命令:select count(*) from tbname; 功能:计数非null结果的数目。 两者配合使用: 命令:select species,count(*) from pet group by species; 功能:查询每种宠物的个数。 6.修改数据 命令:update tbname set 要更改的列 where 条件 举例:update guestbook set visitor='sunnnyboysac' where comments='...'; 说明:更新visitor的值为sunnyboysac 条件是comments=‘...’。 7.删除数据 命令:delete from tbname where 条件 举例:delete from guestbook where visitor=‘sunnyboysac’; 可以用 delete from guestbook;语句删除整个表的数据。 bitscn.com