摘要: 打印出表的结构语句 show columns from 表名 或者 desc 表名,其中desc 表名 是 show columns from表名的一种快捷方式 查看建表的语句用 show create table 表名 使用select选出单列时候,如果数据有重复,却只想选出不同的数据可以在列名前加上distinct关键字 如: select distincv ... 阅读全文
posted @ 2013-11-25 22:01 long896130895 阅读(108) 评论(0) 推荐(0)
摘要: union 合并2条或者多条语句的结果 语法 sql1 union sql2 mysql> select goods_id,goods_name,shop_price from goods where shop_price union -> select goods_id,goods_name,shop_price from goods where shop_price >4... 阅读全文
posted @ 2013-11-25 02:09 long896130895 阅读(249) 评论(0) 推荐(0)
摘要: 理解左连接的查询方式(以两表id相等作为on的条件)左右联结还包括没有关联的行,因此在使用左右联结的时候,必须指出right或者left关键字来指定报刊其所有行的表为从右边的表中选择所有行则使用right 从左边表中选择所有行则使用left左连接语句 select * from test1.a left join test2.b on a.id=b.id说明:先将左表记录依次排成一行或者多行,若无匹配的记录则显示为null在本例中,我画了六根线,每根线都表示了一条查询结果记录当id 为1时:左表有两条id为1的记录,右表只有一条。先查询左表的第一条,然后再查询右表中所有id与左表第一条记录的i 阅读全文
posted @ 2013-11-24 22:46 long896130895 阅读(522) 评论(0) 推荐(0)
摘要: 假设A表在左边不动,B表在A表的右边滑动,A表与B表通过一个关系来筛选B表的行 语法 A left join B on 条件 这一块形成的也是一个结果集,可以看成一张表C ,也可对C表进行查询,则 where group order by limit 照常使用 select goods_id, goods_name goods_number,shop_price,cat... 阅读全文
posted @ 2013-11-24 03:13 long896130895 阅读(138) 评论(0) 推荐(0)
摘要: 一张表就是一个集合 每一行就是一个元素 创建一个类似的表 字段一样 语句如下 create table minigoods like goods;其中 minigoods 是新表 goods是旧表 insert into minigoodsselect * from goods limit 3;从goods表中选出前三行数据,插入到minigoods表中全相乘 ... 阅读全文
posted @ 2013-11-24 02:41 long896130895 阅读(658) 评论(0) 推荐(0)
摘要: 为什么建表时加not null default‘’或者default0 为什么不希望列的值不为null? null是空,null的比较需要特殊的运算符 is null is not null select * from test where name is not null;取出不是null的值 select * from test where name is nul... 阅读全文
posted @ 2013-11-23 22:08 long896130895 阅读(101) 评论(0) 推荐(0)
摘要: 查询模型 列就是变量,在每一行上,列的值都在变化 where条件是表达式,在哪一行上表达式为真,哪一行就取出来,比如 下面的条件,shop_price 在不同的行 有不同的值,在哪一行时,shop_price>500 如果为真,则这一行就取出来 查询结果集在结构上可以当成表看 where的子查询 查询最新的商品 mysql> select goods_name,go... 阅读全文
posted @ 2013-11-23 04:14 long896130895 阅读(297) 评论(0) 推荐(0)
摘要: where是对数据直接处理,having是对产生的结果再进行处理 select goods_id,goods_name,market_price-shop_price as k from goods where market_price-shop_price >200;上语句只能使用 where market_price-shop_price>200 而不能使用 where k... 阅读全文
posted @ 2013-11-22 23:40 long896130895 阅读(179) 评论(0) 推荐(0)
摘要: mysql> select goods_name,shop_price from goods where cat_id=3 and(shop_price5000) and click_count>5;+----------------+------------+| goods_name | shop_price |+----------------+------------+| 多普... 阅读全文
posted @ 2013-11-22 23:08 long896130895 阅读(128) 评论(0) 推荐(0)
摘要: where——group——having——order by——limit 阅读全文
posted @ 2013-11-22 20:08 long896130895 阅读(155) 评论(0) 推荐(0)