1

我有 3 张桌子:TimeTable, Subject, WeekDay.

TimeTable表具有以下字段:SubjectId, WeekDayId

我想向TimeTable表中插入值,但数据来自名称,而不是id.s,所以我想执行这个语句:

Insert into TimeTable SubjectId , WeekDayId 
Select WeekDay.WeekdayId , Subject.SubjectId from weekday , Subject 
Where Subject.SubjectName=IPSubjectName And Weekday.WeekDayName=IPWeekDayName

现在我有两个问题:

  1. 这个语句在 sqlite 中可用吗(我写对了吗)?

  2. 我怎样才能动态地输入这些值(IPSubjectName、IPWeekDayName)。
    ie 如果我有 var SubjectName, var WeekDayName,那么该语句将如何编写?

4

2 回答 2

2
  1. 是的,我认为您编写的语句在 SQLite 中可用。
  2. 我假设您编写了一个调用此查询的 PHP 函数,在这种情况下,您的变量名将变为$SubjectNameand $WeekDayName。然后,您的代码将变为:

    Where Subject.SubjectName=$SubjectName AND Weekday.WeekDayName=$WeekDayName
    
于 2012-07-09T11:51:00.427 回答
0

Pass the values as parameters in the function where you are executing the query and replay the right hand side clause with ${paramname1} and ${paramname2}.

于 2012-07-09T12:18:08.137 回答