1 指定資料排前面
group by nutr_scheme.id order by nutr_scheme.id not in (select scheme_id from nutr_user_default_scheme where user_id = 10036 and is_delete = 0), drink_count desc, nutr_scheme.id asc
2 多行查詢結果合併一行(適用於一對多)
selectgroup_concat(name) as all_name,
`name`
from
base_basedata
group by
pid
3 distinct用於去掉count重複值
count(distinct id) as `count`
4 查詢兩分鐘以內資料
create_time >= unix_timestamp(now()-interval 120 second)
5 時間戳(10位)轉時間
from_unixtime(time_stamp, '%y-%m-%d %h:%i:%s')
6 一對多查詢數量
select `user`.id, `user`.`name`
, user_score.count
from `user`
left join (select user_id
, count(*) count
from user_score
group by user_id) as user_score on user_score.user_id = `user`.id
主表 user 子表 user_score
關係 user_score.user_id = `user`.id
7 distinct,去掉重複值(貌似只對乙個字段有效?)
selectdistinct company from orders
mysql常用語句 MySQL常用語句
create table student id int primary key auto increment comment 學號 name varchar 200 comment 姓名 age int comment 年齡 comment 學生資訊 修改表注釋 alter table studen...
php mysql 常用語句 mysql常用語句
一 修改mysql使用者密碼 mysql h localhost u root p 命令列登入 update user set password password 123456 where user root 二 資料庫操作 show databases 顯示資料庫 create database ...
MySQL常用語句
and和or可以混用,and比or具有更高的優先順序,但盡量使用圓括號區分 自動過濾重複的資料owner,關鍵字distinct select distinct owner from pet 按照生日公升序排列,關鍵字order by select name,birth from pet order...