MySQL常用的查詢語句回顧

來源:互聯網
上載者:User

標籤:

讓你快速複習語句的筆記寶典。

create table users(
   username varchar(20) primary key,
   userpwd varchar(20)
)

alter table users add age int


insert into stu (sname)values(‘sdfdsfdsfeeeeee‘)
update cj set cj=60 where sid=1

delete from cj where sid=2

--所有行所有列

select * from stu
--某一些行所有列
select * from stu where sid>3
--某一些行某一些列
select sname from stu where sid>=3
--某一列所有行
select sname from stu

--mysql中限制m stu limit 3

select * from stu limit 3,2

--排序
select * from stu order by sid asc

--模糊尋找
select * from stu where sname like ‘%aa%‘

--彙總函式使用
select  sum(c.cj) from cj as c

select count(*) from stu

select count(userpwd) from users

--分組
select count(*),age from users group by age
--對分組之後查詢使用having
select count(*),age from users group by age having count(*)>=2

---null查詢
select * from users where userpwd is not null

select * from users where age between 20 and 30
select * from users where username between ‘a‘ and ‘l‘

-- in子查詢
select * from stu where sid in(1,2,3,4,7,6,8,9)

--內串連
select * from stu inner join cj as c on stu.sid=c.`sid`
where stu.sid=1

--等值串連
select * from stu ,cj as c where stu.sid=c.`sid`

--外串連
select * from cj as c right join stu  on stu.sid=c.sid


---子查詢
select * from stu where age>(
   select age from stu where sname=‘lisi‘
   )

轉載自:http://blog.csdn.net/supera_li/article/details/9303709

MySQL常用的查詢語句回顧

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.