我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

MySQL SELECT其中if条件组

Hi this is what I want to do:

to_id: 5 to_type: 1

from_id: 3 from_type: 2

I want to SELECT ALL WHERE to_id = 5 only if to_type = 1 AND I want to select * where from_id = 3 only if from_type = 2.

how can I do this in a single SELECT statement?

Looks like this is what you want

SELECT * FROM foobar WHERE (to_id = 5 AND to_type = 1) OR (from_id = 3 and from_type = 2)

That is, get all rows that either matches to_id = 5 and to_type = 1, or matches from_id = 3 and from_type = 2.

近期文章

  • PHP AES 128位加密/解密
  • OJS-配置变量的位置
  • AttributeError: 'RunTest' object has no attribute 'util'
  • 51单片机最小系统的焊接
  • 有道题让用cookie显示上次登陆该页面的时间,若没有则显示firsttime,但是我写的不管怎么样都是firsttime
  • Java 的一个关于接口和继承方面的基础问题的疑惑,往大佬解答。
  • 将查询字符串附加到任何形式的URL
  • 从XSS攻击中保护PHP会话[关闭]
  • 如何使用PHP限制API请求
  • 将日文字符传递给PhP文件
  • 为什么浏览器不解析内容?
  • Mysql多个时间戳列更新
  • PHP替换数组中的数组值
  • ffmpeg for php以及如何降低噪音
  • 无法将图像上传到magento产品[关闭]
  • 如何结合php Form的两个动作
  • 破解PHP脚本 - fwrite和变量
  • PHPExcel_Style_Fill无限递归
  • CodeIgniter - 所有页面上的购物车
  • 从MySQL获取数组时出错[重复]

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华