一些mysql的sql語句
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=‘三室一廳‘
AND hou.hTid=hty.hTid
AND hou.sid IN
(SELECT sid FROM hos_street AS street INNER JOIN hos_district AS district WHERE street.`sDid`=district.`did` AND district.`dname`=‘西湖區‘)
ORDER BY price LIMIT 0,5
SELECT * FROM hos_house; //查所有房屋信息
SELECT * FROM hos_house WHERE price>500; //租金大於500
SELECT COUNT(*) FROM (
SELECT *,COUNT(*)AS COUNT FROM sys_user GROUP BY uname ORDER BY COUNT DESC
)AS a WHERE a.count>1; //重名的人數
SELECT * FROM sys_user; //查所有用戶信息
SELECT * FROM hos_house AS a INNER JOIN hos_type AS b WHERE a.htid=b.htid AND b.htname = ‘三室一廳‘;
//查所有為三室一廳的房屋
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=‘三室一廳‘)
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=‘西湖區‘
//查詢三室一廳在西湖區的房屋 6
SELECT COUNT(DISTINCT manager)AS COUNT FROM sys_user; //查所有管理員的數量
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 //查詢房屋數量最多的人
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 //查詢西湖區最便宜的5個三居房屋信息和發布人名字
SELECT * FROM (
SELECT * FROM hos_house WHERE price BETWEEN 500 AND 1000
)AS a,hos_street AS b WHERE a.sid=b.sid AND b.sDid=1 ORDER BY price ASC LIMIT 0,5 //以5條記錄為一頁查詢西湖區價格500-1000的房屋
一些mysql的sql語句