-1

我需要有关如何将此选择转换为删除语句的帮助。

SELECT stud_term_sum_div.id_num,   
     stud_term_sum_div.hrs_enrolled,   
     stud_term_sum_div.transaction_sts,   
     student_crs_hist.crs_cde,   
     student_crs_hist.transaction_sts  
  FROM stud_term_sum_div,   
     student_crs_hist  
 WHERE ( stud_term_sum_div.yr_cde = student_crs_hist.yr_cde ) and  
     ( stud_term_sum_div.trm_cde = student_crs_hist.trm_cde ) and  
     ( stud_term_sum_div.id_num = student_crs_hist.id_num ) and  
     ( ( stud_term_sum_div.yr_cde = '2013' ) AND  
     ( stud_term_sum_div.trm_cde = 'FA' ) AND  
     ( stud_term_sum_div.hrs_enrolled >= 3.00 ) AND  
     ( student_crs_hist.transaction_sts = 'D' ) )   
4

1 回答 1

1

最直接的转换如下:

DELETE * FROM stud_term_sum_div
WHERE ( stud_term_sum_div.yr_cde = student_crs_hist.yr_cde ) and  
 ( stud_term_sum_div.trm_cde = student_crs_hist.trm_cde ) and  
 ( stud_term_sum_div.id_num = student_crs_hist.id_num ) and  
 ( ( stud_term_sum_div.yr_cde = '2013' ) AND  
 ( stud_term_sum_div.trm_cde = 'FA' ) AND  
 ( stud_term_sum_div.hrs_enrolled >= 3.00 ) AND  
 ( student_crs_hist.transaction_sts = 'D' ) )

但是,在执行之前,请检查该WHERE子句是否确实包含要用于删除的条件。请注意,当WHERE子句中的属性满足所述条件时,此 SQL 语句将删除整行(a/k/a 记录)。

如果您只想从属性中删除数据(而不是整个记录),则需要使用 SQLUPDATE语句。其(简化)语法如下:

UPDATE <table_name>
SET <attribute1> = <value1>
[, SET <attribute_n> = <value_n>...]
WHERE <conditions on which the record should be updated>

在 Bing、google、<在此处插入您最喜欢的搜索引擎> 上搜索“SQL DELETE”或“SQL UPDATE”应该会得到您需要的所有信息(例如,MSDN)。

于 2013-04-29T16:41:22.733 回答