• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

mysql 查

mysql 搞代码 4年前 (2022-01-09) 26次浏览 已收录 0个评论

获取表本文来源[email protected]搞@^&代*@码)网9有多少行
技巧:

select count(*) from table_name;

取出cat_id=4和cat_id=11的列
使用or select * from goods where cat_id=4 or cat_id=11;
不使用or select * from goods where cat_id in(4,11);

取出价格>=100 且<=500

select * from goods where shop_price >= 100 and shop_price <= 500;select * from goods where shop_price between 100 and 500;

取出价格<=100 且>=500

select * from goods where shop_price <=100 and shop_price >= 500;select * from goods where shop_price not between 100 and 500;

in是散点的集合,between and是区间

cat_id不是3也不是11的列

select * from goods where cat_id!=3 and cat_id!=11;select * from goods where cat_id not in(3,11);

算出比市场价优惠的数值

select goods_id,(market_price-shop_price) as chajia ,goods_name from goods ;

查找本地价格比市场价便宜200以上的

select goods_id,(market_price-shop_price) as chajia ,goods_name from goods where (market_price - shop_price) > 200;

(chajia列是where作用过之后的产生的)

疑点注意:where是对真实表中的数据发挥作用,having可以对where结果进行过滤

select goods_id,(market_price-shop_price) as chajia ,goods_name from goods where chajia > 200;(错误的)

作用相同

select goods_id,(market_price-shop_price) as chajia ,goods_name from goods having chajia>200;

把mian表中的num列中 [20,29]改为20 [30,39]改为30

update mian set num = floor(num/10)*10 where num between 20 and 39;

like模糊查询

截取诺基亚后面的内容

select goods_id ,goods_name,substring(goods_name,4) from goods where goods_name like '诺基亚%';

查找有诺基亚开头的更换为htc(没有更改真实表内容)

select goods_id ,goods_name,concat('htc',substring(goods_name,4)) from goods where goods_name like '诺基亚%';

把诺基亚更换为htc(更改真实表内容)

update goods set goods_name = concat('htc',substring(goods_name,4))where goods_name like '诺基亚%' and cat_id=4;

以上就是mysql 查的内容,更多相关内容请关注搞代码(www.gaodaima.com)!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:mysql 查

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址