sql(case when 条件)

liangling221 liangling221 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
$pro_select ="select a.products_id,a.sgg,a.sdw,a.products_price,a.products_erp,
c.products_id,c.products_name,d.idppbh,d.sppmc
from osc_products a,osc_products_description c,brand d
where a.products_id =c.products_id and a.products_id
in (select b.products_id from brand_area_product b where b.idppbh= d.idppbh
and b.idppbh = '" . $brand . "' //如果b.idppbh没有指定为具体的某个值则去掉and b.idppbh = '" . $brand . "' 这个查询条件,如果指定则加上这个条件)
and c.products_name like '%". $pro_name ."%' ";

如果b.idppbh没有指定为具体的某个值则去掉and b.idppbh = '" . $brand . "' 这个查询条件,如果指定则加上这个条件这个 sql语句怎样改?大家多多指教谢谢,,,

$pro_select ="select a.products_id,a.sgg,a.sdw,a.products_price,a.products_erp,
c.products_id,c.products_name,d.idppbh,d.sppmc
from osc_products a,osc_products_description c,brand d
where a.products_id =c.products_id and a.products_id
in (select b.products_id from brand_area_product b where b.idppbh= d.idppbh
case when 。。。。。。then ....
and b.idppbh = '" . $brand . "'
) and c.products_name like '%". $pro_name ."%' ";
...全文

相关推荐

SQL中的case…when…还能这么用(计算好评率、计算出有条件的字段的数量)

文章目录SQL之CASE WHEN用法详解场景1:有分数score,score=60返回及格,score>=80返回优秀场景2:现老师要统计班中,有多少男同学,多少女同学,并统计男同学中有几人及格,女同学中有几人及格,要求用一个SQL输出结果。场景3:经典行转列,并配合聚合函数做统计,现要求统计各个城市,总共使用了多少水耗、电耗、热耗,使用一条SQL语句输出结果场景4:CASE WHEN中使用子查询,根据城市用电量多少,计算用电成本。假设电能耗单价分为三档,根据不同的能耗值,使用相应价格计算成本。场景5:结合max聚合函数一道真实的面试题 SQL之CASE WHEN用法详解 简单CASE WH

weixin_38666823

SQL多条件判断使用Case When Then

已经博主授权,源码转载自 https://pan.quark.cn/s/fb31e58fca0d sql 存储过程中常见的疑问可供个人使用且易于传播

dns_boom

SQL利用Case When Then多条件判断

sql 存储过程 常见的问题 自己用也可分享

chen10197

MySQL中使用case when 语句实现多条件查询的方法

今天在一个应用中使用到了一个比较特殊的数据查询要求。需要的朋友可以参考下。

weixin_38543749

case when和sum case when 写法及拼接字段

1 case when 写法 2 sum case when 用法 3 select 拼接字段 示例如下: when 2 then 'C' else 'D' end ) as '类型',count(*) as '数量' from table group by orderType

华锅
评论 8
收藏 已收藏
分享
返回顶部
liangling221
疑难问题 22,298 成员 121,727 内容