Mysql更新表通过加入另一个表(Mysql update table by joining another table)
我在桌子下面,
表产品 ,
product_id | name ----------------------- 1 | product 1 2 | Product 2 3 | Product 3 4 | product 4 5 | product 5 . | .... . | ....
表product_to_zone ,
product_id | zone_id -------------------- 1 | 10 1 | 11 2 | 10 2 | 11
有没有办法在product_to_zone表中为我所有未分配的产品添加zone_id 10,11作为默认值(即对于product_id 3,4,5)
I'm having below tables,
Table product,
product_id | name ----------------------- 1 | product 1 2 | Product 2 3 | Product 3 4 | product 4 5 | product 5 . | .... . | ....
Table product_to_zone,
product_id | zone_id -------------------- 1 | 10 1 | 11 2 | 10 2 | 11
Is there any way to add zone_id 10,11 as default for all my unassigned products in product_to_zone table (i.e for product_id 3,4,5 )
原文:https://stackoverflow.com/questions/17610712
更新时间:2020-01-19 12:19
最满意答案
我可能会使用一个简单的
itertools.cycle
来循环执行以下步骤:from itertools import cycle def fancy_range(start, stop, steps=(1,)): steps = cycle(steps) val = start while val < stop: yield val val += next(steps)
你会这样称呼它:
>>> list(fancy_range(0, 20, (4, 2))) [0, 4, 6, 10, 12, 16, 18]
这样做的好处是可以很好地扩展到任意数量的步骤(尽管目前我还没有真正考虑到这一点 - 但也许可以)。
I might use a simple
itertools.cycle
to cycle through the steps:from itertools import cycle def fancy_range(start, stop, steps=(1,)): steps = cycle(steps) val = start while val < stop: yield val val += next(steps)
You'd call it like so:
>>> list(fancy_range(0, 20, (4, 2))) [0, 4, 6, 10, 12, 16, 18]
The advantage here is that is scales to an arbitrary number of steps quite nicely (though I can't really think of a good use for that at the moment -- But perhaps you can).
相关问答
更多-
交替的参数(Alternating params)[2022-04-04]
如您所述,没有“交替参数”符号。 您只能有一个params参数,它必须是最后一个 - 如果您希望将不同类型作为params参数,则可以使用object作为数组类型。 考虑传入由自定义类型组成的列表,该列表保留这些项目的含义。 public class MyType { public int MyNum { get; set; } public string MyStr { get; set; } } Method(ListmyList); There is no "altern ... -
python - 根据公共值加入2个数组/列表的简单方法(python - simple way to join 2 arrays/lists based on common values)[2022-10-02]
可能是重复的,但如果不是: >>> a = [1,2,3] >>> b = [2,3,4] >>> list(set(a) & set(b)) [2, 3] 对于大型列表(外部数据),请参阅此答案 。 Probably a duplicate, but in case it is not: >>> a = [1,2,3] >>> b = [2,3,4] >>> list(set(a) & set(b)) [2, 3] For large lists (external data), see this S ... -
增加包含值的String的简单方法,例如:USER1000(Simple way to increment a String containing a value eg: USER1000)[2023-09-27]
就像是: String un = "USER10000"; int digit = Integer.parseInt( un.replaceAll( "\\D", "" ) ); String newUn = "USER" + ( digit + 1 ); 你可以使用多long如果更合适。 更新: "\\D"也可以改写为"[^\\d]" ,因为它们匹配相同的字符串 something like: String un = "USER10000"; int digit = Integer.parseInt( ... -
nums = [1, 2, 3, 4] newarray = sum(zip(reversed(nums), nums), ())[:len(nums)] >>> print(newarray) (4, 1, 3, 2) 它做了什么,一步一步。 首先, 反转() : >>> list(reversed(nums)) [4, 3, 2, 1] 然后zip() : >>> list(zip([4, 3, 2, 1], [1, 2, 3, 4])) [(4, 1), (3, 2), (2, 3), (1, ...
-
Python:如何在for循环中交替键来修改字典值?(Python: How can I modify dictionary values in a for loop alternating the keys?)[2022-09-02]
因为将[]传递给dict.fromkeys()只会创建一个列表实例,所以dict2所有值实际上都是相同的列表实例。 尝试 dict2 = dict((v, []) for v in dict1.values()) All values of dict2 are actually the same list instance, since passing [] to dict.fromkeys() only creates one list instance. Try dict2 = dict((v, [] ... -
您确实可以在这里使用动态编程方法。 为了简单起见,假设我们只需要找到这种序列seq的最大长度(这将很容易调整解决方案来查找序列本身)。 对于每个索引,我们将存储2个值: 在最后一步增加的元素处结束的交替序列的最大长度(例如, incr [i]) 在最后一步递减的元素处结束的交替序列的最大长度(比如decr [i]) 根据定义,我们假设incr[0] = decr[0] = 1 那么可以递归地找到每个incr [i]: incr[i] = max(decr[j])+1, where j < i and seq ...
-
使用datediff() : select datediff(day, '2000-01-01', getdate()) %2 Use datediff(): select datediff(day, '2000-01-01', getdate()) %2
-
我可能会使用一个简单的itertools.cycle来循环执行以下步骤: from itertools import cycle def fancy_range(start, stop, steps=(1,)): steps = cycle(steps) val = start while val < stop: yield val val += next(steps) 你会这样称呼它: >>> list(fancy_range(0, 20, (4, ...
-
交替点击(Alternating clicks)[2022-06-28]
当然,只需检查文本是什么,并将其他值返回到text()方法 $('#button').click(function () { $('#mydiv').text(function(_, txt) { return txt == 'ok' ? 'ko' : 'ok'; }); }); 小提琴 Sure, just check what the text is, and return the other value to the text() method $('#button' ... -
相关文章
更多- table-Oceanus配置说明
- Lua table(表、数组、字典)
- Lua 元表(Metatable)改变table的行为
- 求教一个 table的css
- Guava集合工具类-Table接口映射处理
- MYSQL使用mysqldump导出某个表的部分数据
- 关于mysql数据库memory表数据重复问题
- 7月最新发布11.2.0.1.2 Patch set update
- Guava学习笔记:Guava新集合-Table等
- hibenate建表约束问题
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)