头歌作业-数据库实验三 数据查询一

数据库实验三 数据查询一

第一关:按条件查询单表的所有字段

use province;
 #代码开始
 #第一题
select * from jdxx where qxmc="开福区";
 #第二题
select * from jdxx where qxmc in("开福区","岳麓区");

 #第三题
select * from jdxx where cs="长沙市" and name="西湖街道";
  
 #代码结束

第二关:查询唯一值

use province
 #代码开始
 
select distinct qxmc from jdxx where sf="湖南省";
select distinct qxmc from jdxx where cs="长沙市";
 
 #代码结束

第三关:统计查询

use province;
#代码开始
#答案1
select count(name)  from jdxx where sf="湖南省";
#答案
select count(name)  from jdxx where cs="长沙市";

select  count(distinct qxmc)  from jdxx where sf="湖南省";
select count(distinct qxmc)  from jdxx where cs="长沙市";

第四关:分组查询

use province;
SELECT sf, count(*) 
FROM jdxx  
GROUP BY sf;  
SELECT cs, count(*) 
FROM jdxx  
GROUP BY cs  
HAVING count(name) > 200;  
SELECT qxmc, count(*) 
FROM jdxx  
WHERE cs = '长沙市'  
GROUP BY qxmc;  

第五关:数据排序

 use province;
 #代码开始
 #第一题
SELECT *  
FROM jdtj  
ORDER BY jdgs DESC  
LIMIT 10;  
 #第二题

SELECT *  
FROM jdtj  
ORDER BY jdgs ASC  
LIMIT 10;  
 #第三题
SELECT *  
FROM jdtj  
WHERE jdgs > 35  
ORDER BY jdgs DESC, sf ASC;  
 #代码结束
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

shix .

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值