Py学习  »  fa06  »  全部回复
回复总数  5
5 年前
回复了 fa06 创建的主题 » mysql sum查询

您可以尝试使用 case when 表达式和 concat() 功能

select case when length(dst)=4 then concat('028030',dst) else dst end as dst,count(*) 
from cdr 
where calldate between '2019-01-01 00:00:00' and '2019-01-31 23:59:59' and 
dst in ('4121', '2006','2011''4124','0280304121', '0280302006','0280302011','0280304124') and length(src)>4 
group by case when length(dst)=4 then concat('028030',dst) else dst end
order by dst
5 年前
回复了 fa06 创建的主题 » 从MySQLWorkbench中的现有列创建带有条件值的新列?

使用 position() 功能

DEMO

select 
    substring(details, 1, POSITION(' ' IN details)) 
from 
    my_table

输出:

value
Wellcare

产科加强生命支持 locate() 可以使用

 select 
        substring(details, 1, LOCATE(' ', details)) 
    from 
        my_table

在下面试试-

DEMO

UPDATE sales_date 
SET    sales_date_type_datetime = STR_TO_DATE(sales_date, '%Y-%m-%dT%H:%i:%s')
5 年前
回复了 fa06 创建的主题 » MySQL从最后50行中选择最高的

尝试使用子查询:

select max(won)
from
(SELECT * from games WHERE game ='case' ORDER BY id DESC LIMIT 50)a
5 年前
回复了 fa06 创建的主题 » 两个聚合函数的mysql和不工作

您需要在group by中指定mc.complaint_type列

SELECT   mc.complaint_type_id,
         mc.complaint_type,
         sum(case when c.is_solved = 1 then 1 else 0 end) + sum(case when c.is_solved = 0 and c.res_user_id is null then 1 else 0 end) as complaints_count,
from  svk_apt_master_complaints mc
left join svk_apt_complaints c on c.complaint_type_id = mc.complaint_type_id and c.is_active = 1 and c.customer_id = 1 and c.association_id = 1
group by mc.complaint_type_id,mc.complaint_type