zoukankan      html  css  js  c++  java
  • c#Dapper mysql按时间段查询和过滤

     #endregion
            /// <summary>
            /// 根据条件获取集合
            /// </summary>
            /// <param name="id">key</param>
            /// <returns>实体</returns>
            public IEnumerable<models.Model.ScanNubProduct> QueryDateSingle(string datestr)
            {
                if (datestr=="oneday")
                {
                   
                        string date =  DateTime.Now.AddDays(-1).ToString("yyyyMMdd");          //昨天时间
                        const string sql = "SELECT *  FROM report_daily_newzsnumtotal_copy WHERE   日期 =@日期" + " and 规格 not like '36%'" + " and 规格 not like '21%'";
                        using (MySqlConnection connection = new MySqlConnection(connstr))
                        {
                            connection.Open();
                            return connection.Query<models.Model.ScanNubProduct>(sql, new { 日期 = date });
                        }
                }
                else if(datestr=="week")
                {
                    string lastday =  DateTime.Now.AddDays(-1).ToString("yyyyMMdd");
                    string weeksday = DateTime.Now.AddDays(-8).ToString("yyyyMMdd");
                    //    const string sql = "SELECT *  FROM report_daily_newzsnumtotal_copy WHERE  日期 between  '20180827'  and '20180830'";
                    //  string where = "WHERE  日期 between  "+ weeksday + " and "+ lastday+ " and 规格 not like 32 and 规格 not like 36 and 规格 not like 21";
                    string where = "WHERE  日期 between  " + weeksday + " and " + lastday + " and 规格 not like '36%'" + " and 规格 not like '21%'";    //过滤规格为36 和21开头的数据
                    return QueryList(where); 
                }
                else
                {
                    return null;
                }
                }
  • 相关阅读:
    求一个数字各个位的数字之和
    二进制和十进制的转换 分别用python和js实现
    pymysql 获取插入数据的主键id
    js03.事件
    02.js运算符
    jsonpath
    01.js控制台
    2.命令补充
    hashmap
    正则表达式的补充
  • 原文地址:https://www.cnblogs.com/zuochanzi/p/9578816.html
Copyright © 2011-2022 走看看