初学数据库1

select * from movies
where name between 'A' AND 'J';

select * from movies where year between 1990 AND 2000;

select * from movies
where year between 1990 and 2000
and genre = 'comedy';

select * from movies
where genre = 'comedy'
or year < 1980;

select * from movies
order by imdb_rating desc;//通过imdb_rating进行降序排序

select * from movies
order by imdb_rating asc
limit 3;//升序排3个

select count(*) from fake_apps;//显示fake_apps这个关系的行数

select count(*) from fake_apps
where price = 0;

select price,count(*) from fake_apps
group by price;//把不同价格分组,显示数目

select price,count(*) from fake_apps
where downloads > 20000
group by price;

select sum(downloads) from fake_apps;//在某一列求和

select category,sum(downloads) from
fake_apps
group by category;//相同category的为一组,求和

select max(downloads) from fake_apps;

SELECT name, category, MAX(downloads) 
FROM fake_apps
GROUP BY category;//相同的category中找最大的downloads并且显示这三个值

select avg(downloads) from fake_apps;//平均值

SELECT price, ROUND(AVG(downloads), 2) //结果保留两位小数
FROM fake_apps
GROUP BY price;

select price,round(avg(downloads))//忽略小数点后面的
from fake_apps
group by price;

//By specifying that the id column is the PRIMARY KEY, SQL makes sure that:

None of the values in this column are NULL
Each value in this column is unique

SELECT * FROM albums
JOIN artists ON
albums.artist_id = artists.id;//把artists表中的一些列加到albums里(条件如上)

select * from albums
left join artists on//left table is simply the first table that appears in the statement
albums.artist_id = artists.id;

select
albums.name as 'Album',
albums.year,
artists.name as 'Artist'
from
albums
join artists on
albums.artist_id = artists.id
where
albums.year > 1980;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值