String
select concat(c1,' ',c2);
SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM users;
select substring(c1,1,3);
length()
SELECT username FROM users WHERE LENGTH(username) < 5;
Math
round(num,3)四舍五入
select a1.machine_id ,round(avg(a2.timestamp - a1.timestamp),3) processing_time
from Activity a1
left join Activity a2 on
a1.machine_id = a2.machine_id and
a1.process_id = a2.process_id and
a1.activity_type = 'start' and
a2.activity_type = 'end'
group by machine_id
date
datediff(c1,c2);
SELECT DATEDIFF(NOW(), '2024-01-01') AS days_since_new_year;
SELECT order_id, order_date, delivery_date
FROM orders
WHERE DATEDIFF(delivery_date, order_date) > 30;
DATEDIFF() 函数返回 date1 和 date2 之间的天数差。请注意,date1 和 date2 的顺序会影响结果的正负值。
聚合函数
count(*) 返回行数,如果(c1)则c1为null不算
sum(c)返回一列的和
avg(c)返回列的平均值
max(),min()