Mysql学习笔记
1、char_length() 求字符串的长度
select tweet_id from tweets where char_length(content) > 15
2、性能问题
这两个sql到底是按个更快一点?
Sql1
select customer_id, count(visit_id) as count_no_trans
from visits where visit_id not in (
select distinct visit_id from transactions
)
group by customer_id
Sql2
select a.customer_id, count(a.customer_id) as count_no_trans
from visits a
left join transactions b on a.visit_id = b.visit_id
where b.transaction_id is null
group by a.customer_id;
3、datediff(date1, date2)获取时间差
select a.id from weather as a
join weather as b on datediff(a.recordDate, b.recordDate) = 1
-- 这里datediff(a.recordDate, b.recordDate) = 1就表示a.date - b.date = 1
where a.temperature > b.temperature;