简单基本的sql语句 几个简单的基本的sql语句
选择:select * from table1 where范围
插入:insert into table1(field1,field2) values(value1,value2)
删除:delete from table1 where范围
更新:update table1 set field1=value1 where范围
查找:select * from table1 where field1 like ’%value1%’
(1) 数据记录筛选:
sql=\"select * from 数据表 where 字段名=字段值 order by 字段名 [desc]\"
sql=\"select * from 数据表 where 字段名 like \'%字段值%\' order by 字段名 [desc]\"sql=\"select top 10 * from 数据表 where 字段名=字段值 order by 字段名 [desc]\"sql=\"select top 10 * from 数据表 order by 字段名 [desc]\"
sql=\"select * from 数据表 where 字段名 in (\'值1\',\'值2\',\'值3\')\"
sql=\"select * from 数据表 where 字段名 between 值1 and 值2\"
(2) 更新数据记录:
sql=\"update 数据表 set 字段名=字段值 where 条件表达式\"
sql=\"update 数据表 set 字段1=值1,字段2=值2 …… 字段n=值n where 条件表达式\"
(3) 添加数据记录:
sql=\"insert into 数据表 (字段1,字段2,字段3 …) values (值1,值2,值3 …)\"
sql=\"insert into 目标数据表 select * from 源数据表\" (把源数据表的记录添加到目标数据表)
(4) 数据记录统计函数:
AVG(字段名) 得出一个表格栏平均值
COUNT(*;字段名) 对数据行数的统计或对某一栏有值的数据行数统计MAX(字段名) 取得一个表格栏最大的值
MIN(字段名) 取得一个表格栏最小的值
SUM(字段名) 把数据栏的值相加
引用以上函数的方法:
sql=\"select sum(字段名) as 别名 from 数据表 where 条件表达式\"
set rs=conn.excute(sql)
用 rs(\"别名\") 获取统计的值,其它函数运用同上。
查询去除重复值:select distinct * from table1between的用法
between限制查询数据范围时包括了边界值,not between不包括
select * from table1 where time between time1 and time2
select a,b,c, from table1 where a not between 数值1 and 数值2
in 的使用方法
select * from table1 where a [not] in (‘值1’,’值2’,’值4’,’值6’)