zoukankan      html  css  js  c++  java
  • 常用SQL

    ##2016年11月24日 group by 分组,如distinct.

    select * from mch_msg_order group by order_id  

    结果集是:按照id asc排序,筛选出记录

    SELECT * FROM (SELECT * FROM `mch_msg_order` ORDER BY `to_status` DESC) t GROUP BY `order_id` ORDER BY `to_status` DESC

    按照to_status排序,在结果集中分组,即可获取to_status最大的不重复的记录

    ##2016年9月20日  两个字段相加

    select id,(sale+virtual_sale) as c from mch_wechat_product_info

    ##2016-07-21 对于导出excel为科学计数法的数据,使用concat转化

    SELECT u.`realname` ,u.`phone` ,concat('订单',g.`wxnumber`) as wx, g.number FROM `wm_barter_goods` as g left join wm_barter_users as u on g.usersId = u.id WHERE g.`cTime` > 1468944000 

    ##2016-04-01 常用sql

    alter table wm_m_wechat_list add constraint UQ_openid UNIQUE(openid)

    ##2016-03-16  选择数量大于1的数据

    select * ,count(id) as num from wm_m_wechat_list GROUP BY openid HAVING num>1

  • 相关阅读:
    SpringMVC框架(2)
    SpringMVC框架(1)
    (数据结构与算法)跳表实现
    第2次作业
    第1次作业
    第一次作业
    第一周作业.
    第一周作业
    第0次作业
    第一次作业
  • 原文地址:https://www.cnblogs.com/linglingyang/p/5077939.html
Copyright © 2011-2022 走看看