删除某字段值为空的所有记录
delete from tasks where task_id is Null
同时从两张表里取数据,这个功能真是太强大了,以前一直没留意使用它。
select tasks.id,tasks.subject,tasks.definition,tasks.creator,taskaccessories.label from tasks,taskaccessories where tasks.id=taskaccessories.task_id and tasks.id=347
这是目前我写过最为复杂的一条sql语句
意为从task表中取出id,subject值,并且部门名称是从另一张表中根据id值取出来的。
select id,subject from tasks where department=(select name from taskdepartment where id =".$_SESSION['departid'].") and opentime is not null and assigntime is null
又进一步了。
select id,subject from tasks where id not in(select task_id from taskapplicator where applicator='".$_SESSION['user']."' and applytime is not null ) and department=(select name from taskdepartment where id =".$_SESSION['departid'].") and opentime is not null and assigntime is null");
删除id为348,352,364的数据的记录
delete from taskaccessories where id in(348,352,364)
将时间转化格式为这样:2009-09-17 22:07:24 如果没有加粗的部分,原来的样式为如此的17-SEP-09
select id,subject,department,creator,to_char(opentime,'yyyy-mm-dd hh24:mi:ss') as opentime from tasks where opentime is not null and assigntime is null
选出tasks表中所有的相关信息但不包括id=$_GET['id']
select id,subject from tasks where opentime is not null and assigntime is null and id not in '".$_GET['id']."'
那个关联任务,如果是在A任务里添加了一个B任务做关联,
那么B任务里是不是也要显示下A任务做为他的关联任务的啊。
select id,subject,creator,department from tasks where id in(select relate_id from taskrelation where task_id='290')
union
select id,subject,creator,department from tasks where id in(select task_id from taskrelation where relate_id='290')
select * from quser order by id desc
desc 表示降序,asc表示升序
/*oracle中创建自动编号*/ 意为序列号从5开始,因为oracle当中没有自动编号这个功能只能用这样的语句来创建CREATE SEQUENCE seq_taskappraise start with 5 NOMAXVALUE NOCYCLE NOCACHE;
insert into taskappraise(id,task_id,appraiseor,appraise,appraisetime) values(seq_taskappraise.nextval,'290','无159影刀','非常GOOD 168',sysdate)
/*删除一个字段*/
alter table taskappraise drop column score
/*删除多个字段*/
alter table tasks drop (appraise,appraisetime);
/*评分 插入一个字段*/
alter table tasks add score number(5)
/*修改一个字段的内容*/
update tasks set definition = '这是新修改的内容' where id =290
/*修改多个的内容*/
UPDATE tasks SET subject = '12134545',definition = '123123132' WHERE id =1