1 Após o agrupamento da filtragem dos resultados
Selecione o nome do campo a ser exibido 1, o nome do campo a ser exibido 2, a função do grupo de nomes de tabelas pelo nome do campo a ser exibido 1, o nome do campo a ser exibido 2 Tendo condições;
例如:/* 地区的男女人数>1的,且性别不为其他的*/
SELECT guestArea,guestSex,COUNT(*) FROM guestinfo
GROUP BY guestArea,guestSex
HAVING COUNT(*)>1 AND guestSex NOT LIKE '%其他%'
2) Resumo (resultados agrupados)
Select 要显示的字段名1 ,函数() from 表名 group by 要显示的字段名1
With rollup.
例如:
查询出每个地区的人数,并且汇总
SELECT guestArea,COUNT(*) FROM guestinfo GROUP BY guestArea WITH ROLLUP
3) Consulta de conexão
1. Interconexão
Select * from 表名1 inner join 表名2 on 表名1.字段名=表名2.字段名(注意:字段名相同)
例如:查询嘉宾表和商品表里的数据,并且要求显示的guestid相同且不为空
SELECT * FROM guestinfo INNER JOIN productinfo
ON guestinfo.guestId=productinfo.guestid
2) Consulte o conteúdo correspondente:
SELECT guestinfo.guestName 姓名,guestinfo.guestsex 性别,
productinfo.productname 产品名,productinfo.productprice 价格
FROM guestinfo
INNER JOIN productinfo
ON guestinfo.guestId=productinfo.guestid
3) Consulta de várias tabelas
Select * from 表名1 ,表名2 where 表名1.字段名=表名2.字段名(注意:字段名相同)
4) Conexão externa
(1)左外连接
Select * from 表名1 left join 表名2 on 表名1.字段名=表名2.字段名(注意:字段名相同)
(2)右外连接
Select * from 表名1 right join 表名2 on 表名1.字段名=表名2.字段名(注意:字段名相同)