douyong1885 2016-01-08 04:37
浏览 19
已采纳

父子关系,不使用PHP获取并重新使用返回值[关闭]

I'm trying to make a relation between two tables. I can do what I want with fetching the data with PHP and using returning value again in a query. But as far as I researched, it doesn't seem an efficient method.

How can I get the winning coupons when I'm finalizing the bet #3 as YES with a SQL query?

(It should return 3 and 4)

Coupon table,

ID coupon_id bets bets_played  played_by
0    2        2       yes         JOHN
1    2        3       no          JOHN
2    3        1       yes         JANE
3    3        3       yes         JANE
4    4        3       yes         SARAH
5    4        2       no          SARAH

Bets table,

ID  result
1    yes
2    no
3    NULL

Thank you.

  • 写回答

1条回答 默认 最新

  • doushihu5475 2016-01-08 04:55
    关注
    select distinct c.*
    from coupon c
    join bets b on b.result = c.bets_played and b.result = 'yes'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥15 对于这个问题的算法代码
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题