Some SQL statements for MySQL

Source: Internet
Author: User


SELECT hou.*,uname from Hos_house as Hou
INNER JOIN Sys_user as usr
INNER JOIN Hos_type as Hty
On Hou.uid=usr.uid
And Hty.htname= ' three rooms and one hall '
and Hou.htid=hty.htid
and Hou.sid in
(SELECT SID from Hos_street as street INNER joins Hos_district as District WHERE Street. ' Sdid ' =district. ' Did ' and district . ' Dname ' = ' West L. District ')
ORDER by Price LIMIT 0,5



SELECT * from Hos_house; Check all housing Information
SELECT * from Hos_house WHERE price>500; Rent greater than 500

SELECT COUNT (*) from (
SELECT *,count (*) as Count from Sys_user GROUP by uname ORDER by COUNT DESC
) as a WHERE a.count>1; Number of names

SELECT * from Sys_user; Check all user Information

SELECT * from Hos_house as a INNER JOIN Hos_type as B WHERE a.htid=b.htid and b.htname = ' three rooms and one hall ';
Check all the houses for the three rooms and one hall

SELECT * FROM (SELECT * from Hos_house where htid=1) as a,hos_street as B where A.sid=b.sid and b.sdid=1;


Select C.hmid from (select A.hmid,a.price,a.sid from Hos_house as a,hos_type as B WHERE a.htid=b.htid and b.htname= ' three rooms and one hall ')
As C INNER join Hos_street as D INNER join Hos_district as E WHERE c.sid=d.sid and D.sdid=e.did and E.dname= ' West L. District '
Find three rooms and one hall in West L. District House 6


SELECT count (DISTINCT Manager) as COUNT from Sys_user; Check the number of all administrators

SELECT N.uid,n.uname,max (N.house) as House from (
SELECT S.uname,s.uid,count (*) as House from (
SELECT S.uname,h.uid from Hos_house as h,sys_user as S WHERE s.uid=h.uid
) as S GROUP by S.uid ORDER by house DESC
As N//search for people with the largest number of houses

SELECT * FROM (
SELECT A.hmid,a.price,a.htid,b.sdid,a.uid,c.dname from (
SELECT * from Hos_house WHERE htid=1
As a,hos_street as b,hos_district as C WHERE a. Sid=b.sid and sdid=1 and C.did=b.sdid ORDER by Price ASC LIMIT 0,5
As c,sys_user as D WHERE c.uid=d.uid//query West L. District cheapest 5 three-bedroom house info and publisher name


SELECT * FROM (
SELECT * from Hos_house WHERE price between and 1000
As a,hos_street as B WHERE A.sid=b.sid and b.sdid=1 order by price ASC LIMIT 0,5//with 5 records for one page query West L. District price 500-1000 of the house

Some SQL statements for MySQL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.