例如区别人的字段为name,年份字段为Ndate,则SQL如下
创新互联建站长期为近1000家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为西林企业提供专业的成都网站建设、成都做网站,西林网站改版等技术服务。拥有十载丰富建站经验和众多成功案例,为您定制开发。
-- 查明细
select * from tb where name='yy' and Ndate between '2017-01-01 00:00:00' and '2017-12-31 23:59:59'
-- 查总分平均分
select sum(score),avg(score) from tb where name='yy' and Ndate between '2017-01-01 00:00:00' and '2017-12-31 23:59:59'
我假定你的入职日期字段格式为date,并且字段名为 t_date,那么下面这条语句可能可以满足你的要求.
select * from( SELECT year(now())-year(t_date) as t_year FROM `test_t` where year(t_date) 1990 ) as tmp_data where t_year 10
====================
说明一下思路:
子查询计算出入职的年数,并将结果添加字段别名t_year,这个语句只select了t_date字段,其他字段请按需要添加.
SELECT year(now())-year(t_date) as t_year FROM `test_t` where year(t_date) 1990
然后使用另一条查询来得到大于10年的职工.
select * from (子查询语句) as temp_data where t_year10
select left(times,4), sum(coun) from tablename group by left(times,4) order by left(times,4)
上面代码中tablename 就是你的表名
一、SQL语句统计每年的销售总额
select year(ordertime) 年,
sum(Total) 销售合计
from 订单表
group by year(ordertime)
二、SQL语句统计每月的销售总额
select year(ordertime) 年,
month(ordertime) 月,
sum(Total) 销售合计
from 订单表
group by year(ordertime),
month(ordertime
三、SQL语句统计每日的销售总额
select year(ordertime) 年,
month(ordertime) 月,
day(ordertime) 日,
sum(Total) 销售合计
from 订单表
group by year(ordertime),
month(ordertime),
day(ordertime)
扩展资料
mysql查询每天、每周、每月的数据方法
一、查询每天的数据
SELECT
COUNT(1) AS countNumber,
DATE_FORMAT(createTime,'%Y-%m-%d') AS dateTime
FROM
testTable
GROUP BY DATE_FORMAT(createTime,'%Y-%m-%d')
二、查询每周的数据
SELECT
COUNT(1) AS countNumber,
WEEK(createTime) as dateTime
FROM
testTable
GROUP BY WEEK(createTime)
三、查询每月的数据:
SELECT
COUNT(1) AS countNumber,
MONTH(createTime) as dateTime
FROM
testTable
GROUP BY MONTH(createTime)
参考资料:
百度百科SQL语句大全
select DATE_FORMAT(来电时间,'%Y-%m') as 月, 问题类别 , count(1) as 数量 from
( select 来电时间, 问题类别 from mytable where 问题类别 = '农村用水投诉' ) tmptable
group by DATE_FORMAT(来电时间,'%Y-%m') ,问题类别 ORDER BY 月 ASC;