mysql 查询月份下有多少条数据

mysql 查询月份下有多少条数据,第1张

想获取指定book_id下的每月借阅次数。月份不存在该表时,数量为0

有bookborrowing表和month表

如上sql语句只能统计所有的分月数量,不能指定book_id。

SELECT

DATE_FORMAT(m.month,'%Y-%m') AS `日期`,

COUNT(b.book_id) AS 数目

FROM

mon m LEFT JOIN book_borrowing b ON (DATE_FORMAT(m.month,'%Y-%m') = DATE_FORMAT(b.book_borrowingtime,'%Y-%m'))

GROUP BY

m.month

您好,

SELECT art_id, art_pdate

FROM ecos_article

WHERE art_id>75 limit 0,1

UNION

SELECT art_id, art_pdate

FROM ecos_article

WHERE art_id<=75 ORDER BY art_id DESC limit 0,3

效果如下:

mysql>SELECT art_id, art_pdate FROM ecos_article limit 0,5

+--------+------------+

| art_id | art_pdate |

+--------+------------+

| 73 | 2005-12-01 |

| 74 | 2005-12-01 |

| 75 | 2005-12-01 |

| 76 | 2005-12-01 |

| 77 | 2005-12-01 |

+--------+------------+

mysql>SELECT art_id, art_pdate

->FROM ecos_article

->WHERE art_id>75 limit 0,1

->UNION

->SELECT art_id, art_pdate

->FROM ecos_article

->WHERE art_id<=75 ORDER BY art_id DESC limit 0,3

+--------+------------+

| art_id | art_pdate |

+--------+------------+

| 76 | 2005-12-01 |

| 75 | 2005-12-01 |

| 74 | 2005-12-01 |

+--------+------------+


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/7648902.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-08
下一篇2023-04-08

发表评论

登录后才能评论

评论列表(0条)

    保存