DAY(date) 返回date的天数部分
HOUR(time) 返回time的小时值(0~23)
MINUTE(time) 返回time的分钟值(0~59)
SECOND(time) 返回time的秒值(0-59)
DATE(datetime) 返回datetime的日期值
TIME(datetime) 返回datetime的时间值
SELECT
t.myYear AS 年份,
t.monthNo AS 月份,
count(1) AS 数量统计
FROM
(
SELECT
MONTH (pi_gym_enter.create_date) AS monthNo, //这里指定日期字段为 create_date
YEAR (pi_gym_enter.create_date) AS myYear,
pi_gym_enter.id AS id
FROM
pi_gym_enter WHERE getr_member_id = 5 // 这里指定用户
) AS t
WHERE
t.myYear = '2018' // 这里指定年份
GROUP BY
t.monthNo;
select * from bean where date(usedate) = date_sub(curdate(),interval 1 day);
// 括号中为当天时间的前一天,如果统计前几天就将括号中的’1’改成相应的天数。
SELECT
getr_member_id,
DATE(create_date),
sum(getr_time),
create_date
FROM
pi_gym_enter
WHERE
getr_member_id = 5
AND (
`create_date` BETWEEN '2018-03-01 00:00:00'
AND '2018-04-01 00:00:00'
)
GROUP BY
DATE(create_date)
SELECT T1.C1,T2.CX,T3.CY
FROM TAB1 T1
INNER JOIN TAB2 T2 ON (T1.C1=T2.C2)
INNER JOIN TAB3 T3 ON (T1.C1=T2.C3)
LEFT OUTER JOIN TAB4 ON(T2.C2=T3.C3);
WHERE T1.X >T3.Y;
SELECT DISTINCT a.sname,
(SELECT score FROM stdscore b WHERE a.sname=b.sname AND b.CNAME='JAVA' ) AS 'JAVA',
(SELECT score FROM stdscore b WHERE a.sname=b.sname AND b.CNAME='mysql' ) AS 'mysql'
FROM stdscore a
网友评论