--【指定數據庫】
use demo
go
--【1】查詢表的所有數據
--【語法】select * from 表名
select * from hanshu
--【2】查詢表中的列
--【語法】select 列名1,列名2,列名3..... from 表名
select name from hanshu
--【3】查詢表中列名為女的數據,或者是id=1,或者是add='湖南益陽'
--【語法】select * from 表名 where sex='女'
select * from hanshu where sex='女'
--【4】查詢表中name字段包含湯的數據
--【語法】select * from 表名 where 列名 like '湯%'
select * from hanshu where name like '湯%'
--【5】查詢表字段moeny中5到12之間的數據
--【語法】select * from 表名 where 列名 between 數字 and 數字
select * from hanshu where moeny between 5 and 12
--【6】查詢表字段moeny中2.5.20數據
--【語法】select * from 表名 where 列名 in(2,5,20)
select * from hanshu where moeny in(2,5,20)
--【7】求表中moeny的平均值
--【語法】select avg(列名) from 表名
select avg(moeny) from hanshu ;
--【8】求表中moeny的總和
--【語法】select sum(列名) from 表名
select sum(moeny) from hanshu ;
--【9】求表中字段moeny小於20的數據
--【語法】select * from 表名 where 字段名<20
select * from hanshu where moeny<20
