經常使用數據庫語句

  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

相關文章
相關標籤/搜索