duanhao1004 2015-12-10 14:43
浏览 40
已采纳

如何用这个表结构从MySQL实现结果?

I have a table that looks like this:

id  content_id  fields_id   value_int   value_string    value_decimal

351 3           1                       204 
352 3           2                       Western Cape    
353 3           3                       Cape Town   

365 4           1                       205 
366 4           2                       District of Columbia    
367 4           3                       Washington

365 4           1                       204 
366 4           2                       Eastern Cape    
367 4           3                       Jeffreys Bay    

This repeats for thousands of listings.

Now what I want to do, is write a query that I feed the ID (i.e 204, which is a country ID) - fields_id 1.

Then it must give me a result of a distinct list of all the states / provinces (the value string of fields_id 2) for country ID 204, for instance.

My MySQL skill are on the basic side, so could you please give an idea of how to achieve this in a query?

  • 写回答

2条回答 默认 最新

  • doune1000 2015-12-10 15:14
    关注

    This SQL statement will do what you want:

    SELECT w.id, w.value_string  
    FROM Table1 o
    LEFT JOIN Table1 w ON w.id = (o.id + 1)
    WHERE o.value_string = '204'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用