du20150401 2014-10-30 15:34
浏览 34
已采纳

混合数据库中两个表的数据

I have two tables, one called location_name it looks like this,

location  shortname longname  precolor     color     hidden

       1    STO     Stockholm   #00FF00     #FF0000     0
       2    GBG     Gothenburg  #00FFFF     #FF00FF     0
       3    MMO     Malmö      #C6C6C6     #008000     0
       4    CPH     Copenhagen  #FF0080     #FF8000     0
       5    ARH     Ã…rhus      #80FF80     #8000FF     1
       6    SER     Service     #FFFF00     #FFFF00     1

and the other one, called art_tot, looks lite this

artnr   art     art_text     gnr       gnr_group    sortorder   hide    location    
220101  Thing   description  2201      1            101         0       3
220102  Thing   description  2201      1            102         0       2 
220103  Thing   description  2201      1            103         0       3 

and im making a that looks something like this

 Pos    Equipment   Artnr  Mon 27-10-2014   Tue 28-10-2014  Wed 29-10-2014  Thu 30-10-2014  Fri 31-10-2014  Sat 01-11-2014  Sun 02-11-2014
 STO    Thing       220101
 STO    Thing       220102
 STO    Thing       220103
 STO    Thing       222001

What i need to do is, color the Pos to the correct color from location_name and have the correct shortname and have the title be the longname.

So i somehow have to make the the Pos TD get the correct values from location_name based on the location column from art_tot

Or is there a simpler way to do this?

  • 写回答

1条回答 默认 最新

  • drug95107 2014-10-30 20:17
    关注

    i read about JOIN and ended up doing :

    $sql ="SELECT a.art_text , a.art , a.art , a.artnr , b.color , b.longname, b.shortname
            FROM art_tot a , location_name b 
            where gnr_group =1 AND a.location = b.location
            order by sortorder" ;
    

    It works like a charm, thanks @dwhite.me

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏