工作中经常会遇到,要在sql中查询报表,查询结果要求按照日期来罗列, 或按照天, 或按照月,年. 这个时候我们经常会苦恼,datetime是精确到毫秒的,如果单纯的group by datetime就会导致结果不正确. 这是我们可以利用convert函数: SELECT convert(varchar(10),CreateDate,120) ,var1 ,var2 FROM Table GROUP BY convert(varchar(10),CreateDate,120) ASC 第一个参数是
SELECT `menuid`, SUM(`num`)AS total, `storeid`, DATE_FORMAT(`dateline`,'%Y-%m-%d') days FROM loss WHERE `storeid` = 2 GROUP BY days,menuid -- 查询 月 周 天 select DATE_FORMAT(create_time,'%Y%u') weeks,count(caseid) count from tc_case group by weeks; selec
好书分享,面向开发者的Azure SQL Database最佳实践,也适用SQL Server 2016以上的版本.应对不同场景使用的数据库功能,包括内存表,列存储表,非聚集列存储索引,JSON等等. 下载地址: https://all-ebook.info/9978-practical-azure-sql-database-for-modern-developers.html 基础SQL Subqueries Common Table Expressions Union Merge MERGE
using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication2 { internal class Program { private static void Main(string[] args) { DataTable dt = n
mysql方法来源于:http://www.cnblogs.com/jjcc/p/5896588.html ###在网上看到一篇,非常赞的方法### 比如说要获取班级的前3名,mysql就可以用GROUP_CONCAT + GROUP BY + substring_index实现. 考试表 DROP TABLE IF EXISTS `test`;CREATE TABLE `test` (`id` int(11) DEFAULT NULL,`name` varchar(20) DEFAULT N
mysql> select accid as uid,date(datetime) AS datetime from game.logLogin GROUP BY accid HAVING datetime='2013-8-20'; +---------+------------+ | uid | datetime | +---------+------------+ | | -- | | | -- | +---------+------------+ rows in set (0.00 sec