赞
踩
select CONCAT('用户名' ,'01') from user
SELECT DISTINCT b.garageId,
b.AccepterDate
FROM
(
SELECT garageId,MAX(AccepterDate) AS AccepterDate FROM behavior GROUP BY garageId
) a
LEFT JOIN p_recordbehavior b ON a.garageId = b.garageId
AND a.AccepterDate = b.AccepterDate
SET @i=0;
select systime,(@i:=@i+1)'序号' from zh_testing as a where flag=0
SELECT DATE_FORMAT(NOW(),'%Y-%m-%d %H:%i:%s');
1.使用 cese when
ORDER BY case when t.UpdateTime is null then t.createtime else t.UpdateTime end desc
having子句用于筛选分组之后的各种数据,通常与“group by”联合使用,该语句弥补了where关键字无法与聚合函数联合使用的不足。
having 后面可以使用 count , sum
SELECT gongcheng_id,count(1) from gcx_yanghu_repair GROUP BY gongcheng_id HAVING count(1)>1
select d.AQ_LH_ID,b.AQ_ID from aq_jcb as b LEFT JOIN aq_lhjcd as d on d.AQ_LH_ID =left(b.AQ_ID, 10)
select d.AQ_LH_ID,b.AQ_ID from aq_jcb as b LEFT JOIN aq_lhjcd as d on d.AQ_LH_ID =left(b.AQ_ID, 10)
where instr(b.AQ_yhnr, "sss") > 0
同上图
拼接后使用","分割
select GarageId,GROUP_CONCAT(station_id) from p_aggregate_station GROUP BY GarageId
参考链接:
https://blog.csdn.net/Martin_chen2/article/details/121407417
使用 in() 查询数字时,常常会有引号,如“1,2,3”,进而只查询第一个数字,影响查询结果,使用FIND_IN_SET () 则不会有这有这种情况。
SELECT sheshi as sheshimingc FROM `cn_point` WHERE BM_CODE in(546,833) GROUP BY sheshi;
SELECT sheshi as sheshimingc FROM `cn_point` WHERE FIND_IN_SET(BM_CODE,"546,833") GROUP BY sheshi ;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。