首页 > 解决方案 > Names of months as names of columns in MySQL

问题描述

I need to create table where first column is names of clients and next ones are months of previous year starting from current month with amount of orders of user in this month. So my problem is that I don't really know how to name columns as months starting from current. I know that i can get name of month with namemonth() but i can't use it as name of column. Any ideas?

标签: mysql

解决方案


如果我理解正确,您想动态命名您的列。如果你真的想这样做,你可以用你最喜欢的编程语言为此编写一个脚本。但我不建议你这样做,因为这不是一个好的做法。

这就是我要做的:

创建一个包含 3 列的表,第一列是客户端的名称或 id(int 或 varchar 类型),第二列是日期(日期类型),第三列是值(int 类型的数量)订单只能是整数)。然后,您可以编写一个脚本来使用基于日期的脚本来获取特定(或所有)客户的订单数量。

但是,如果您真的想做您所说的,我真的不建议这样做,请查看 Progman 在他的评论中提供的链接。


推荐阅读