首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从时间戳列中选择特定的月份和年份记录mysql

问从时间戳列中选择特定的月份和年份记录mysql
EN

Stack Overflow用户
提问于 2019-05-19 22:32:01
回答 1查看 21关注 0票数 0

我试图做的是选择和统计特定月份和年份的患者的诊断结果。我已经选择并统计了诊断,我的问题是如何在特定的月份和年份选择它。

我的查询SELECT diagnosis, count(diagnosis) as total from patient_records where deleted_at is null group by diagnosis

表结构patient_records

代码语言:javascript
复制
#   Name    Type    Collation   Attributes  Null    

1   idPrimary   int(10)     UNSIGNED    No

2   diagnosis   varchar(191)    utf8_unicode_ci     

3   remarks text    utf8_unicode_ci     Yes NULL             

4   created_at  timestamp           Yes NULL             

5   updated_at  timestamp           Yes NULL             

6   deleted_at  timestamp           Yes NULL             

7   patient_id  int(10)     UNSIGNED    Yes NULL             

请帮助我,我是一个初学者,在我脑海中的问题是这样的

代码语言:javascript
复制
 SELECT diagnosis, count(diagnosis) as total from patient_records where 
 deleted_at is null and updated_at = month(5)&year(2019) group by 
 diagnosis
EN

回答 1

Stack Overflow用户

发布于 2019-05-20 00:43:07

代码语言:javascript
复制
SELECT 
  diagnosis, 
  count(diagnosis) as total,
  DATE_FORMAT(created_at, '%m') As month, 
  YEAR(created_at) as Year 
from patient_records 
where deleted_at is null 
group by diagnosis
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56208797

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档