douci2015 2019-03-23 16:28
浏览 41

如何插入新数据,同时将一些数据保持为多个行的常量

I've these tables:

Days

day_id     day
     1     Monday
     2     Tuesday

schedule

schedule_id    session
          1    Start
          2    Breakfast
          3    Lunch

Ingredients

ing_id    ing_name
     1    Whey Protein
     2    Havermout
     3    Water Cup

and main_table

week_id | (user_id) | (day_id) | (schedule_id) | (ingredient_id) | grams

NOTE:

Columns surrounded by parenthesis in the main_table are foreign Keys from their respective tables.

Here is what I want to achieve:

For example I want to populate the data in main_table something like this

(I've populated this table manually)

I want to keep the first four column's data (in main_table ) as constant until the schedule_id does not change , and insert new data in the next two columns i.e ingredients_id and grams.

Because it works like this: Each week has days, days has sessions and in different session/timings user would be able to eat different ingredients.

Meaning that for one specific week, number of days could be repeated as here

and for one day number of schedule session can be repeated , similarly for each schedule session there could be many ingredients.

How can I make some data as constant for some columns, and update some columns while inserting.

Do I need to change the structure of my tables, if so please suggest any other way to achieve this .

I really tried my best to explain my problem in simple way.

Thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?