Compare commits
8 Commits
1a2212ad54
...
8439ea1f37
Author | SHA1 | Date | |
---|---|---|---|
![]() |
8439ea1f37 | ||
![]() |
5ce0db0c27 | ||
![]() |
155d5aa380 | ||
![]() |
cbd24d1714 | ||
![]() |
8bdb573a81 | ||
![]() |
81fed4392d | ||
![]() |
3fdd06a507 | ||
![]() |
9ccd5e1a89 |
13
数据库/头歌/AVG() 函数的使用/AVG() 函数的使用.sh
Normal file
13
数据库/头歌/AVG() 函数的使用/AVG() 函数的使用.sh
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
USE Mall
|
||||||
|
GO
|
||||||
|
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
------ return two columns that the price bigger than average price ------
|
||||||
|
-- ********** Begin ********** --
|
||||||
|
SELECT prod_name, prod_price
|
||||||
|
FROM Products
|
||||||
|
WHERE prod_price > (SELECT AVG(prod_price) FROM Products)
|
||||||
|
-- ********** End ********** --
|
||||||
|
|
||||||
|
GO
|
14
数据库/头歌/COUNT() 函数的使用/1. COUNT() 函数的使用.sh
Normal file
14
数据库/头歌/COUNT() 函数的使用/1. COUNT() 函数的使用.sh
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
USE Mall
|
||||||
|
GO
|
||||||
|
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
------ return the number of product which price bigger than 10 -----
|
||||||
|
-- ********** Begin ********** --
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM Products
|
||||||
|
WHERE prod_price > 10
|
||||||
|
-- ********** End ********** --
|
||||||
|
|
||||||
|
GO
|
||||||
|
|
22
数据库/头歌/使用WHERE语句进行检索/使用WHERE语句进行检索.sh
Normal file
22
数据库/头歌/使用WHERE语句进行检索/使用WHERE语句进行检索.sh
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
USE Mall
|
||||||
|
Go
|
||||||
|
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
---------- retrieving with range ----------
|
||||||
|
-- ********** Begin ********** --
|
||||||
|
SELECT prod_name, prod_price
|
||||||
|
FROM Products
|
||||||
|
WHERE prod_price BETWEEN 3 AND 5;
|
||||||
|
-- ********** End ********** --
|
||||||
|
|
||||||
|
GO
|
||||||
|
|
||||||
|
---------- retrieving with nomatches ----------
|
||||||
|
-- ********** Begin ********** --
|
||||||
|
SELECT prod_name, prod_price
|
||||||
|
FROM Products
|
||||||
|
WHERE prod_name <> 'Lion toy';
|
||||||
|
-- ********** End ********** --
|
||||||
|
|
||||||
|
GO
|
22
数据库/头歌/基本SELECT查询/基本SELECT查询.sh
Normal file
22
数据库/头歌/基本SELECT查询/基本SELECT查询.sh
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
USE Mall
|
||||||
|
GO
|
||||||
|
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
---------- retrieving multiple column ----------
|
||||||
|
-- ********** Begin ********** --
|
||||||
|
SELECT prod_name, prod_price
|
||||||
|
FROM Products;
|
||||||
|
|
||||||
|
-- ********** End ********** --
|
||||||
|
|
||||||
|
GO
|
||||||
|
|
||||||
|
---------- retrieving all column ----------
|
||||||
|
-- ********** Begin ********** --
|
||||||
|
SELECT *
|
||||||
|
FROM Products;
|
||||||
|
|
||||||
|
-- ********** End ********** --
|
||||||
|
|
||||||
|
GO
|
20
数据库/头歌/带限制条件的查询和表达式查询/带限制条件的查询和表达式查询.sh
Normal file
20
数据库/头歌/带限制条件的查询和表达式查询/带限制条件的查询和表达式查询.sh
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
USE Mall
|
||||||
|
Go
|
||||||
|
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
---------- retrieving with limited ----------
|
||||||
|
-- ********** Begin ********** --
|
||||||
|
SELECT prod_name
|
||||||
|
FROM Products
|
||||||
|
WHERE prod_name LIKE '%toy%'
|
||||||
|
-- ********** End ********** --
|
||||||
|
GO
|
||||||
|
|
||||||
|
---------- retrieving with expression ----------
|
||||||
|
-- ********** Begin ********** --
|
||||||
|
SELECT prod_price, prod_price * 0.8 AS discount_price
|
||||||
|
FROM Products
|
||||||
|
WHERE prod_price > 3
|
||||||
|
-- ********** End ********** --
|
||||||
|
GO
|
36
数据库/头歌/数据的更改/数据的更改.sh
Normal file
36
数据库/头歌/数据的更改/数据的更改.sh
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
-- ********** create database ********** --
|
||||||
|
-- ********** Begin ********** --
|
||||||
|
create database Books
|
||||||
|
-- ********** End ********** --
|
||||||
|
go
|
||||||
|
|
||||||
|
use Books
|
||||||
|
go
|
||||||
|
|
||||||
|
-- ********** create table ********** --
|
||||||
|
-- ********** Begin ********** --
|
||||||
|
create table prices
|
||||||
|
(
|
||||||
|
ID int IDENTITY(1,1) not null,
|
||||||
|
Name varchar(20) not null,
|
||||||
|
price varchar(30) not null
|
||||||
|
)
|
||||||
|
-- ********** End ********** --
|
||||||
|
go
|
||||||
|
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
-- ********** insert ********** --
|
||||||
|
-- ********** Begin ********** --
|
||||||
|
insert into prices (Name, price) values ('Harry Potter', '$128')
|
||||||
|
insert into prices (Name, price) values ('Walden', '$5')
|
||||||
|
-- ********** End ********** --
|
||||||
|
go
|
||||||
|
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
-- ********** update ********** --
|
||||||
|
-- ********** Begin ********** --
|
||||||
|
update prices set price = '$6' where Name = 'Walden'
|
||||||
|
-- ********** End ********** --
|
||||||
|
go
|
13
数据库/头歌/通配符%的使用/1. 通配符%的使用.sh
Normal file
13
数据库/头歌/通配符%的使用/1. 通配符%的使用.sh
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
USE Mall
|
||||||
|
Go
|
||||||
|
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
---------- retrieving with wildcard % ----------
|
||||||
|
-- ********** Begin ********** --
|
||||||
|
SELECT prod_id, prod_name, prod_price
|
||||||
|
FROM Products
|
||||||
|
WHERE prod_name LIKE '%toy%'
|
||||||
|
-- ********** End ********** --
|
||||||
|
|
||||||
|
GO
|
15
数据库/头歌/通配符_的使用/通配符_的使用.sh
Normal file
15
数据库/头歌/通配符_的使用/通配符_的使用.sh
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
USE Mall
|
||||||
|
Go
|
||||||
|
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
---------- retrieving with wildcard _ ----------
|
||||||
|
-- ********** Begin ********** --
|
||||||
|
|
||||||
|
SELECT prod_id, prod_name, prod_price
|
||||||
|
FROM Products
|
||||||
|
WHERE prod_name LIKE '1_ inch%'
|
||||||
|
|
||||||
|
-- ********** End ********** --
|
||||||
|
|
||||||
|
GO
|
Loading…
x
Reference in New Issue
Block a user