MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
changsha
V2EX  ›  MySQL

请教 sql 语句

  •  
  •   changsha · Oct 11, 2014 · 3513 views
    This topic created in 4297 days ago, the information mentioned may be changed or developed.
    SELECT * FROM product 
    
    left join product_name on product_name.product_id = product.id
    left join product_price on product_price.product_id = product.id
    left join name_country on name_country.name_id  = product_name.id
    left join price_country on price_country.price_id = product_price.id
    where name_country.country_id = 1
    and price_country.country_id = 1
    

    表结构如下

    想实现本地化(并且需要可排序),所以这么设计,不知道有没有更好的方法。

    Alt text

    如何才能不 where 2 个表的 country_id 呢?因为需要本地化的信息还很多,可能拆分出10个小表。这样就需要 where 10 个表的 country_id

    7 replies    2014-10-11 16:36:39 +08:00
    heaton_nobu
        1
    heaton_nobu  
       Oct 11, 2014
    我经验比较浅,没见过这样的表结构设计
    如果你觉得改动很多country_id麻烦的话可以设一个变量
    TangMonk
        2
    TangMonk  
       Oct 11, 2014
    建议查考下一些开源的ecommerce表结构, prestashop什么的
    coosir
        3
    coosir  
       Oct 11, 2014   ❤️ 1
    难道不是把name和price放到一个表里面……
    oott123
        4
    oott123  
       Oct 11, 2014 via Android
    本地化和拆表有啥关系…
    你直接一个表放进去不行么,一行就是一个语言,然后另外搞个表关联相同商品的不同行。
    product_i18n
    |--product_id--|--piece-id--|--language--|
    product_piece
    |--id--|--name--|--....--|
    shyrock
        5
    shyrock  
       Oct 11, 2014
    说实话没看明白name表和name_country表的设计,意思是name_country表包含了对name的本地化字符串?
    changsha
        6
    changsha  
    OP
       Oct 11, 2014
    @coosir
    @oott123
    @shyrock

    本地化拆分是,不要有冗余信息,相同语言的value,[可选择不用]重新本地化,也可以选择[本地化]。
    imn1
        7
    imn1  
       Oct 11, 2014
    这头像真气人,我抓起报纸想去驱赶……&%@(*@&)@#&(*^$^!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2847 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 01:42 · PVG 09:42 · LAX 18:42 · JFK 21:42
    ♥ Do have faith in what you're doing.