dongtuo5262 2011-05-06 12:35
浏览 63
已采纳

显示多个MySQL表中的数据

I have 14 tables (one for every year) with product code, firm name and invoice numbers. Main structure of table is identical (product code, ID), but there can be some variables in names of firms.

Table2011
| ID | productcode | firm1 | firm2 | firm3 | etc |
| 1  | G-00001     | 2;5;40| 32;67 |       | 150 |
| 2  | G-00005     |       | 50    |       |     |
|etc |             |       |       |       |     |

Table2010
| ID | productcode | firm1 | firm2 | firm3 |etc |
| 1  | G-00001     | 1;10  |       |  55   |    |
| 2  | G-00003     |       | 2     |       |    |
| 3  | G-00005     |       | 50    |  40   |    |
| etc|             |       |       |       |    |

Table2009
...

Column Firm1 do not usually equals to same firm as firm 1 in other table

I am using table editor to work with tables (adding columns to table, editing values…).

I would like to know if it is possible to achieve result like below. It is above my PHP skills.

Product G-00001 page

…
<UL>
<LI>Year 2011: 150etc; 67firm2; 40firm1; 32firm2; 5firm1; 2firm1</LI>
<LI>Year 2010: 55firm3; 10firm1; 1firm1</LI>
<LI>Year 2009: ...</LI>
...
</UL>
…
  • 写回答

2条回答 默认 最新

  • douao1579 2011-05-06 12:50
    关注

    Lemme begin with book recommendation : SQL Antipatterns. You will need it, doesn't matter if you caused this mess or ar just assigned to fix it.

    If i was in your place, first thing would do would be to fix the database structure. This is madness. You do not need a new table for each year and new column for each company. Database is not a form of Excel spreadsheet.

    Invoices             Years          Companies
     -----------------      -------------     ---------------
    | product_code PK |    | year_id  PK |   | company_id PK |
    | company_id   FK |    | number      |   | title         |
    | amount          |     -------------     ---------------
    | year_id      FK |
     -----------------
    

    Where PK - primary key and FK - foreign key.

    This structure would make the gathering of information much much much MUCH easier.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂