经常使用数据库语句

  1. 更新某个字段的值
    UPDATE click SET num = num +1 WHERE name = "input_value"
    数据库中设置num字段,not null default 0.避免null异常。
  2. 分组,对分组字段排序
    select dmname from t_dmlogin_log group by dmname order by dmname desc
  3. 分组,对组内排序

select machine_name, count(machine_name) from t_agents where t_agents.dmaccount is not null and t_agents.dmaccount != ""
and t_agents.dmaccount not like "test_%"
and t_agents.dmaccount in
(
select dmname from t_dmlogin_log where DATEDIFF(t_dmlogin_log.createtime, '2016-6-3') = 0 
group by dmname having dmname in
(
select dmacct from t_vm_infos where dmacct is not null and dmacct != "" and status = 3
)
)
group by machine_name数据库

select  * from t_agents where t_agents.dmaccount is not null and t_agents.dmaccount != ""
and t_agents.dmaccount not like "test_%"
and t_agents.dmaccount in
(
select dmname from t_dmlogin_log where DATEDIFF(t_dmlogin_log.createtime, '2016-5-30') = 0 
group by dmname having dmname in
(
select dmacct from t_vm_infos where dmacct is not null and dmacct != "" and status = 3
)
)spa

相关文章
相关标签/搜索