SQL语句
我把金钱献给你
每临大事有静气。
展开
-
复制A表指定字段的内容到B表的几种情况
A表字段:id(自动递增),name,pwd,noteB表字段:id(自动递增),name,pwd,note(1)将A表id为1的记录的name,pwd,note字段内容插入B表的name,pwd,note字段:INSERT INTO `B`(`name`,`pwd`,`note`) (SELECT `name`,`pwd`,`note` FROM `A` WHERE `id`='1')(2)将A表的id为1的记录复制,还插入A表:INSERT INTO `A`(`name`,`pwd`,`note`) (原创 2010-12-28 15:08:00 · 3878 阅读 · 0 评论 -
无意中查sql中as的用法搜索到的一些经典的sql语句
<br />总结一些工作中用到或碰到的SQL语句,希望能与大家分享,同时也希望大家能提供更多的精妙SQL语句.....<br />1、delete table1 from (select * from table2) as t2 where table1.id=t2.id<br />2、truncate table table1 (不在事务日志中做记录,比delete table快,但不能激活触发器)<br />3、update table1 set column=column+1 where id=(se转载 2011-01-10 15:37:00 · 1027 阅读 · 0 评论 -
sql子查询用法
在数据库的查询过程中,可能经常要用到子查询的情况,用得较多的可能是嵌套子查询,最近查资料时发现还有另外一种方法,就是在from子句中使用子查询,也可以实现相同的效果,下面通过一个实例来讲讲这两种方法的使用。 问题:查询员工工资高于其所在部门平均工资的员工的信息 1.使用嵌套子查询的方法。 select * from Employee e1 where e1.salary> (se转载 2011-11-25 11:27:24 · 701 阅读 · 0 评论 -
mysql下sql语句令某字段值等于原值加上一个字符串
MYSQL在一个字段值后面加字符串,如下: member 表名 card 字段名 update member SET card = '00' || card; (postgreSQL 用 || 来连贯字符串) MySQL连贯字符串不能利用加号(+),而利用concat。 比方在aa表的name字段前加字符'x',利用: update aa转载 2012-04-04 14:16:25 · 15003 阅读 · 1 评论 -
常用sql
以下时间均以unix时间戳存储的,为数字 ----------------------------------------------------- //今天所有学生注册记录 SELECT * FROM `student` WHERE regTime > UNIX_TIMESTAMP( curdate() ) //2011-04-26以后的订单 SELECT `order_i原创 2011-05-19 11:04:00 · 687 阅读 · 0 评论 -
SQL重复记录查询
1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断 select * from people where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1) 例二: select * from testtable wh转载 2012-12-27 09:33:26 · 384 阅读 · 0 评论 -
各数据库要使用保留字的处理办法
oracle:将字段名加双引号(“”) 如: select “user” from table1 sql server 和 access:将字段名加中括号([]) 如:select [user] from table1 mysql:将字段名加反引号(``) 如:select `user` from table1原创 2013-08-13 10:36:15 · 1617 阅读 · 0 评论