問題タブ [update-statement]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票する
1 に答える
748 参照

sql - How to update the Bridge table in SQL Server?

I have three tables tblSubject, tblSubjectGroup and tblSubjectGroupDetails.

tblSubject table has the following columns:

tblSubjectGroup table has these columns:

tblSubjectGroupDetails is the bridge table between the above tables which have a many-to-many relationship:

I put the following dummy data in these tables:

tblSubject:

English, Mathematics, Physics, Chemistry, Science, Biology, Economics, Geography, History

tblSubjectGroup:

Group1, Group2,Group3

  • Group1 is linked to English, Mathematics and Biology
  • Group2 is linked to Geography, History and Economics
  • Group3 is linked to Physics, Chemistry and Science

Here, I want to update the Group2 with these subjects: Geography, History, Science.

(Inserting and deleting is fine for me, but I can't figure out how to update the bridge table)

The above statement will change all the subjects of a particular subjectGroup. I want to change only Economics to Science for Group2.

By the way, I forgot to mention that tblSubjectGroupDetails has a composite primary key.

How can I do this in SQL Server?

0 投票する
3 に答える
73 参照

sql - 同じユーザー ID 内の複数のレコードの同じ値を更新する SQL 更新クエリはありますか?

計算のみに使用される列があります。休暇時間を表す 0 または正の数値が表示されます。時間テーブルでは、負の数として入力され、計算のために正の数に変換します。従業員による各エントリの NonWorkHrs 列に正の値が入る必要があります。ユーザー ID 内のすべてのレコードで同じ値である必要があります。

サブクエリ内で case ステートメントと select max を使用してみました

ケースステートメントも試しました

VacationHours 列で、負の TimeEntered 値を正の値に変換します。NonWorkHrs 列は、実際の作業時間を決定するために計算で使用されます。

期待される結果は

実際の結果は