1、查詢專案位址address為空的建立人姓名和專案名稱;
select
a.name,
b.name
from
user a,
project b
where a.id=b.user_id
and b.address ='';
select a.name,c.name1 from user a inner join (
select b.user_id,b.name as name1 from project b where b.address='') as c
on a.id=c.user_id;
2、查詢建立專案最多的使用者id、姓名和專案數量
select
a.id,
a.name,
count(b.user_id)
from
user a,
project b
where a.id=b.user_id
group by b.user_id
order by count(b.user_id) desc limit 1;
select a.id,a.name,c.total from user a inner join (
select b.user_id,count(b.user_id) as total from project b group by b.user_id order by count(b.user_id) desc limit 1) as c
on a.id=c.user_id;
3、查詢建立時間在2015至2023年之間的專案id、專案名稱和建立時間
select id,name,createtime from project where createtime between "2015-01-01" and "2018-12-31";
select id,name,createtime
from project
where substring(createtime,1,4) >= 2015
and substring(createtime,1,4) <= 2018
4、查詢沒有在天津和上海建立專案的使用者id和姓名
select
a.id,
a.name
from
user a,
(select distinct(b.user_id) from project b where b.address !='上海' and b.address!='天津')
as e
where
a.id=e.user_id;
select a.id,a.name from user a where a.id in (
select distinct(b.user_id) from project b where b.address !='上海' and b.address!='天津');
5、查詢在天津和上海都建立了專案的使用者id和使用者姓名
select
a.id,
a.name
from
user a,
(select distinct c.user_id from
(select b.user_id from project b where b.address='天津' ) as c
inner join (select p.user_id from project p where p.address='上海' ) as d
on c.user_id =d.user_id
as e
where
a.id=e.user_id;
select a.id,a.name from user a where a.id in (
select distinct(b.user_id) from project b where b.user_id in
(select b.user_id from project b where b.address ='上海') and b.address='天津');
mysql語句高階 Mysql高階SQL語句
show columns from table name from database name 或show columns from database name.table name 或show fields 解釋 顯示表中列名稱 和 desc table name 命令的效果是一樣的 檢視連線數,...
mysql執行語句 mysql執行sql語句過程
流程概述 mysql得到sql語句後,大概流程如下 1.sql的解析器 負責解析和 sql 2.預處理器 對解析後的sql樹進行驗證 3.查詢優化器 得到乙個執行計畫 4.查詢執行引擎 得到資料結果集 5.將資料放回給呼叫端。流程圖如下所示 分發器及快取階段 首先,如果系統的快取功能開啟著的話,sq...
怎麼查詢mysql的語法 MySQL查詢語法
select distinct productname from custom where product price between 5 and 10 order by product price desc product name limit 3 offset 1 limit 限定從1行開始選出...