精华内容
下载资源
问答
  • 假设有3字串 abc,123,yui 我要找某字段存在包含这三字串的值存在,那么得写: select * from table where...select * from table where item like '%' (集合) ‘%’ 这样的语句解决这种问题? 谢谢指教 ^_^
  • 和SQL Server数据库的查询一样,SQLite数据库也有几个特殊的查询也是比较使用的,...下划线 _ 匹配一个字符串 百分号 % 匹配多个字符串 LIKE 匹配字符串时不区分大小写 LIKE查询的代码实例如下: 1 sqlit...

    SQL Server数据库的查询一样,SQLite数据库也有几个特殊的查询也是比较使用的,比如说:LIKE查询IN集合查询等,本文介绍了这一部分查询的实例代码,接下来我们就来一一介绍。

    LIKE

    • LIKE 用通配符匹配字符串
    • 下划线 _ 匹配一个字符串
    • 百分号 % 匹配多个字符串
    • LIKE 匹配字符串时不区分大小写

    LIKE查询的代码实例如下:

     

     1 sqlite> 
     2 
     3  
     4 
     5 sqlite> SELECT * FROM Cars WHERE Name Like '____';  
     6 
     7  
     8 
     9 Id Name Cost  
    10 
    11  
    12 
    13 ---- --------------- ---------------  
    14 
    15  
    16 
    17 1 Audi 52642  
    18 
    19  
    20 
    21 sqlite> 
    22 
    23  
    24 
    25 sqlite> SELECT * FROM Cars WHERE Name Like '%en';  
    26 
    27  
    28 
    29 Id Name Cost  
    30 
    31  
    32 
    33 ---- --------------- ---------------  
    34 
    35  
    36 
    37 6 Citroen 21000  
    38 
    39  
    40 
    41 8 Volkswagen 21600  
    42 
    43  
    44 
    45 sqlite> 
    46 
    47  
    48 
    49 sqlite> SELECT * FROM Cars WHERE Name Like '%EN';  
    50 
    51  
    52 
    53 Id Name Cost  
    54 
    55  
    56 
    57 ---- --------------- ---------------  
    58 
    59  
    60 
    61 6 Citroen 21000  
    62 
    63  
    64 
    65 8 Volkswagen 21600  
    66 
    67  
    68 
    69 sqlite>

     

     

     

    GLOB

    • GLOB 用通配符匹配字符串
    • 下划线 ? 匹配一个字符串
    • 百分号 * 匹配多个字符串
    • LIKE 匹配字符串时,区分大小写

    BETWEEN 值1 AND 值2

    返回两个值之间的数据集合。下面的语句查询价格在 20000 到 55000 之间的车,都是好车啊。代码如下:

     

     1 sqlite> 
     2 
     3  
     4 
     5 sqlite> SELECT * FROM Cars WHERE Cost BETWEEN 20000 AND 55000;  
     6 
     7  
     8 
     9 Id Name Cost  
    10 
    11  
    12 
    13 ---- --------------- ---------------  
    14 
    15  
    16 
    17 1 Audi 52642  
    18 
    19  
    20 
    21 4 Volvo 29000  
    22 
    23  
    24 
    25 6 Citroen 21000  
    26 
    27  
    28 
    29 7 Hummer 41400  
    30 
    31  
    32 
    33 8 Volkswagen 21600  
    34 
    35  
    36 
    37 sqlite> 

     

     

     

    IN (集合)

    对应列的值必须在集合中。下面的语句查找奥迪和悍马的价格。IN集合查询的代码如下:

     

     1 sqlite> 
     2 
     3  
     4 
     5 sqlite> SELECT * FROM Cars WHERE Name IN ('Audi','Hummer');  
     6 
     7  
     8 
     9 Id Name Cost  
    10 
    11  
    12 
    13 ---- --------------- ---------------  
    14 
    15  
    16 
    17 1 Audi 52642  
    18 
    19  
    20 
    21 7 Hummer 41400  
    22 
    23  
    24 
    25 sqlite> 

     

     

     

    关于SQLite数据库中LIKE查询和IN集合查询的例子就介绍到这里,希望能对您有所帮助。

    转载于:https://www.cnblogs.com/greywolf/archive/2012/06/30/2571029.html

    展开全文
  • Array-like 的对象集合JavaScript 有一种“类似数组的对象”,它是一个对象的数组,并且带有一个length的属性。比如:var realArray = ['a', 'b', 'c']; var arrayLike = { 0: 'a', 1: 'b', 2: 'c', length: 3 }...

    Array-like 的对象集合

    JavaScript 有一种“类似数组的对象”,它是一个对象的数组,并且带有一个length的属性。比如:

    var realArray = ['a', 'b', 'c'];
    var arrayLike = {
      0: 'a',
      1: 'b',
      2: 'c',
      length: 3
    };

    最普通的例子是html中的 document.getElementByTagName 或 document.querySelectorAll 返回的 NodeList 或 HTMLCollection。

    但是,Arrays 和 Array-like 的对象集合有一个关键的不同点是:Array-like 的对象集合继承于 object.prototype 而不是 Array.prototype。这意味着 Array-like 的对象集合不能访问通用的数组方法,比如: foreach(), push(), map(), filter(), slice()。

    var parent = document.getElementById('myDropdown');
    var desiredOption = parent.querySelector('option[value="desired"]');
    var domList = parent.children;
    
    domList.indexOf(desiredOption); // Error! indexOf is not defined.
    domList.forEach(function() { 
      arguments.map(/* Stuff here */) // Error! map is not defined.
    }); // Error! forEach is not defined.
    
    function func() {
      console.log(arguments);
    }
    func(1, 2, 3);   // → [1, 2, 3]

    把 Array-like 的对象集合转换成数组的方式如下:

    • Array.from
    const arrayLike = {
      0: 'Value 0',
      1: 'Value 1',
      length: 2
    };
    arrayLike.forEach(value => {/* Do something */}); // Errors
    const realArray = Array.from(arrayLike);
    realArray.forEach(value => {/* Do something */}); // Works
    • for…of
    var realArray = [];
    for(const element of arrayLike) {
      realArray.append(element);
    }
    • Spread operator
    [...arrayLike]

    归纳多个值

    reduce() 方法用一个函数累加数组中的每个值(从左到右)从而得到一个新值。

    求合:

    [1, 2, 3, 4].reduce(function(a, b) {
      return a + b;
    });
    // → 10

    第2个可选参数可以传递给reduce(),它的值将可以用作第一次调用回调函数(也就是function(a, b))的第一个参数(也就是a):

    [2].reduce(function(a, b) {
      console.log(a, b); // prints: 1 2
      return a + b;
    }, 1);
    // → 3
    • 把对象集合变成一个单独的对象:
    var array = [
      {
        key: 'one',
        value: 1
      },
      {
        key: 'two',
        value: 2
      },
      {
        key: 'three',
        value: 3
      }
    ];
    >=ES5.1
    array.reduce(function(obj, current) {
      obj[current.key] = current.value;
      return obj;
    }, {});
    
    >=ES6
    array.reduce((obj, current) => Object.assign(obj, {
      [current.key]: current.value
    }), {});
    
    >=ES7
    array.reduce((obj, current) => ({...obj, [current.key]: current.value}), {});

    结果是:

    {
      one: 1,
      two: 2,
      three: 3
    }

    使用 Map 进行 Reduce

    另一个使用初始化参数的例子是:在一个数组上调用一个函数,在一个新数组中返回结果。因为数组都是普通的值,而列表级连(list concatenation )是一个普通的函数,我们可以用 reduce 累加一个列表,比如这样:

    function map(list, fn) {
      return list.reduce(function(newList, item) {
        return newList.concat(fn(item));
      }, []);
    }
    
    // Usage:
    map([1, 2, 3], function(n) { return n * n; });
    // → [1, 4, 9]
    • 找最大值或最小值:
    var arr = [4, 2, 1, -10, 9]
    
    arr.reduce(function(a, b) {
      return a < b ? a : b
    }, Infinity);
    // → -10
    • 找唯一值:
      空数组作为第2个参数,被prev引用:
    var arr = [1, 2, 1, 5, 9, 5];
    
    arr.reduce((prev, number) => {
      if(prev.indexOf(number) === -1) {
        prev.push(number);
      }
      return prev;
    }, []);
    // → [1, 2, 5, 9]

    Mapping

    通常需要根据一个现有的数组生成一个新的数组,比如,生成一个字符串的数组的有关其字符串长度的数组:

    >=ES5.1
    ['one', 'two', 'three', 'four'].map(function(value, index, arr) {
      return value.length;
    });
    // → [3, 3, 5, 4]
    
    >=ES6
    ['one', 'two', 'three', 'four'].map(value => value.length);
    // → [3, 3, 5, 4]

    匿名函数提供给 map() 函数,map 函数将会为数组中的每个元素调用它,提供的参数按如下顺序:

    • 元素自己;
    • 元素的索引(0,1…);
    • 整个数组;

    另外,map() 提供一个可选的第2参数,作用是设置 mapping 中 this 的值。取决于执行环境,默认的 this的值可能区别很大:

    • 默认值
    ['one', 'two'].map(function(value, index, arr) {
      console.log(this); // window (the default value in browsers)
      return value.length;
    });
    • 改成自定义的对象:
    var obj = {
      documentation: 'randomObject'
    };
    
    ['one', 'two'].map(function(value, index, arr) {
      console.log(this); // Object { documentation: "randomObject" }
      return value.length;
    }, obj);
    展开全文
  • sql编程接收一个集合 介绍 (Introduction) Most IT professionals started their studies or careers by learning programming languages like Basic, Cobol, C, Pascal, Java and so on. Those languages ...

    sql编程接收一个集合

    介绍 (Introduction)

    Most IT professionals started their studies or careers by learning programming languages like Basic, Cobol, C, Pascal, Java and so on. Those languages produce results using a sequence of operations or procedures. For this reason, this approach is called procedural programming.

    大多数IT专业人员通过学习诸如Basic,Cobol,C,Pascal,Java等编程语言来开始他们的研究或职业。 这些语言使用一系列操作或过程来产生结果。 因此,这种方法称为过程编程

    In SQL Server, we can find an equivalent language called Transact SQL, also known as T-SQL. But SQL Server is a database engine and we can do a lot more than just tell him how to produce results: with data management instructions at our disposal like SELECT statement or Common Tabular Expressions feature, we can tell SQL Server what we want to get instead and let it deduct the « how ».

    在SQL Server中,我们可以找到一种称为Transact SQL的等效语言,也称为T-SQL。 但是SQL Server是数据库引擎,我们不仅可以告诉他如何产生结果,还可以做更多的事情:利用诸如SELECT语句或Common Tabular Expressions功能之类的数据管理指令,我们可以告诉SQL Server我们想要得到什么并扣除“如何”。

    As an example, if we want to list customers who bought something last week, in T-SQL, we will write a SELECT query on a Customers table, join it to an Invoices table and filter on an InvoiceDate column. In regular programming language, we would have to write a program which does everything that is performed by SQL Server database engine plus what we want to get: open Invoices and Customers list files, read it one row at a time and create the results set then close it.

    举个例子,如果我们想谁买了东西上周,在T-SQL表的客户,我们将编写一个客户表的SELECT查询,它加入到发票表和过滤上InvoiceDate列。 使用常规编程语言,我们将必须编写一个程序,该程序执行SQL Server数据库引擎执行的所有工作以及我们想要获得的一切:打开“ 发票和客户”列表文件,一次读取一行并创建结果集,然后关闭它。

    This means that operations in SQL Server are performed on a complete set of rows and returns a subset of the rows it manipulated.

    这意味着SQL Server中的操作是在一组完整的行上执行的,并返回它所处理的行的子集。

    As a SQL Server professional, we must be aware of the power of a database engine and get the best out of it, not simply see Transact SQL as another procedural language! Furthermore, if T-SQL is designed for set manipulation, we could expect performance improvement using this « set-based » approach.

    作为SQL Server专业人员,我们必须意识到数据库引擎的功能并充分利用它,而不仅仅是将Transact SQL视为另一种过程语言! 此外,如果T-SQL是为集合操作而设计的,则可以期望使用这种“基于集合”的方法来提高性能。

    This article is the first part of a series of three articles that will deal with set-based programming. In this article, we will focus on the simple “problem” of getting the minimum and maximum values of a column, so as its sum. We will first discuss about different T-SQL instructions and objects that we will use to actually implement solutions using both approaches. Then we will have a look at details of these implementations. While this “problem” can be easily solved by a complete T-SQL beginners, even not aware of set-based programming approach, it will help us to reveal some points of interest in building a deeper knowledge on set-based approach.

    本文是有关基于集合的编程的三篇文章系列的第一部分。 在本文中,我们将重点介绍获取列的最小值和最大值及其总和的简单“问题”。 我们将首先讨论用于实际使用这两种方法实现解决方案的不同T-SQL指令和对象。 然后,我们将看一下这些实现的细节。 尽管一个完整的T-SQL初学者可以轻松地解决这个“问题”,即使他们不了解基于集合的编程方法,它也将帮助我们揭示一些兴趣点,以便对基于集合的方法进行更深入的了解。

    T-SQL对象和指令 (T-SQL objects and instructions)

    In this section, we will consider the instructions to be used to implement the example of this article. As explained above, this example is totally silly but it is there to pinpoint the power of SQL Server database engine, even for simple operations. By the way, this reflects what could be done applications that do not use a Database Engine.

    在本节中,我们将考虑用于实现本文示例的说明。 如上所述,该示例完全是愚蠢的,但即使在进行简单操作时也可以精确地确定SQL Server数据库引擎的功能。 顺便说一句,这反映了不使用数据库引擎的应用程序可以做什么。

    Procedural objects and instructions in T-SQL

    T-SQL中的过程对象和指令

    There are a few procedural objects and instructions that can be used by a developer to perform a given task.

    开发人员可以使用一些程序对象和指令来执行给定的任务。

    Firstly, we have control-flow operators that we can find in regular programming languages: WHILE, BREAK, CONTINUE, IF…ELSE, TRY…CATCH…

    首先,我们有可以在常规编程语言中找到的控制流运算符: WHILEBREAKCONTINUEIF ... ELSETRY ... CATCH ...

    Secondly, there are cursors. Cursors are especially useful for applications that need to process one row at a time. It can be seen as a double linked list.

    其次,有游标 。 游标对于需要一次处理一行的应用程序特别有用。 可以将其视为双链表。

    Microsoft defines a T-SQL cursor as:

    Microsoft将T-SQL游标定义为:

    They are based on the DECLARE CURSOR syntax and are used mainly in Transact-SQL scripts, stored procedures, and triggers. Transact-SQL cursors are implemented on the server and are managed by Transact-SQL statements sent from the client to the server. They may also be contained in batches, stored procedures, or triggers.

    它们基于 DECLARE CURSOR 语法,主要用于Transact-SQL脚本,存储过程和触发器中。 Transact-SQL游标在服务器上实现,并由从客户端发送到服务器的Transact-SQL语句管理。 它们也可能包含在批处理,存储过程或触发器中。

    Like INT, VARCHAR and other data types, Cursors are declared in T-SQL batches. SQL Server comes with associated instructions to manage it:

    与INT , VARCHAR和其他数据类型一样,游标在T-SQL批处理中声明。 SQL Server附带了相关的说明来对其进行管理:

    • OPEN to tell SQL Server to run the query and populate cursor with results set; OPEN告诉SQL Server运行查询并使用结果集填充游标;
    • CLOSE to tell SQL Server to release resources used by cursor; CLOSE指示SQL Server释放游标使用的资源;
    • FETCH to tell SQL Server to retrieve a specific row from cursor. When we use this function, we can get the outcome of FETCH instruction in @@FETCH_STATUS variable. If it’s set to 0, this means that the instruction succeeded.
    • 指示SQL Server从游标中检索特定行的FETCH 。 使用此函数时,可以在@@ FETCH_STATUS变量中获取FETCH指令的结果。 如果将其设置为0,则表示指令成功。

    Set-based instructions in T-SQL

    T-SQL中基于集合的指令

    In T-SQL, for this set-based approach, we will use so called « aggregate functions ». These functions perform a calculation on a set of values and produce a single value.

    在T-SQL中,对于这种基于集合的方法,我们将使用所谓的“ 聚合函数 ”。 这些函数对一组值执行计算并产生单个值。

    Functions we will use in following example (sum, max, min) are good candidates as aggregate functions. Actually, they are implemented in SQL Server and optimized so that we could get the best out of SQL Server database engine.

    我们将在以下示例中使用的函数(sum,max,min)是合计函数的良好候选者。 实际上,它们是在SQL Server中实现并进行了优化,以便我们可以充分利用SQL Server数据库引擎。

    If you were to find, for instance, the total amount of time they spent on SQLShack (with the assumption that there is a table populated to keep track of user activity), you would need to use the GROUP BY instruction to tell SQL Server that you want the return of SUM aggregate function per user.

    例如,如果要查找他们在SQLShack上花费的总时间(假设已填充一个表来跟踪用户活动),则需要使用GROUP BY指令来告诉SQL Server您想要每个用户返回SUM聚合函数。

    Summary

    摘要

    As a summary, you will find below a table with the instructions and objects at our disposal to write procedural or set-based code. This table will be reviewed at the end of following articles.

    作为总结,您将在下面的表格中找到说明和对象,以编写程序或基于集合的代码。 该表将在以下文章结尾处进行审核。

    Procedural Approach Set-Based Approach
    SELECT and other DML operations,

    WHILE,
    BREAK,
    CONTINUE,
    IF…ELSE,
    TRY…CATCH…
    Cursors (OPEN, FETCH, CLOSE)
    DECLARE
    SELECT and other DML operations,

    Aggregate functions (MIN, MAX, AVG, SUM…)
    程序方法 基于集合的方法
    SELECT和其他DML操作,


    BREAK
    继续
    如果...否则
    试着抓…
    游标OPENFETCHCLOSE
    宣布
    SELECT和其他DML操作,

    汇总函数 (MIN,MAX,AVG,SUM…)

    示例实现 (Example implementations)

    In this section, we will use the instructions and objects defined above to implement a solution to the problem of getting values for min, max and sum of a given column.

    在本节中,我们将使用上面定义的指令和对象来实现解决方案,以获取给定列的最小值,最大值和总和的值。

    We will fist create a table and populate it with some data. Then review an example of implementation for a procedural approach and its noticeable aspects and we will do the same for set-based approach implementation. Finally, compare results and conclude.

    我们将首先创建一个表,并用一些数据填充它。 然后,回顾一下过程方法及其明显方面的实现示例,对于基于集合的方法实现,我们将做同样的事情。 最后,比较结果并得出结论。

    Example setup

    设置示例

    Let’s say we have the following table:

    假设我们有下表:

     
    CREATE TABLE #Example1 (
        ValueInt    INT
    ) ;
     
    

    and populate it with random data

    并用随机数据填充

     
    INSERT INTO #Example1
    SELECT 
        ABS(CHECKSUM(NewId())) % 20
    GO 10
     
    

    If we take a look at its content, we will get something like this:

    如果我们看一下它的内容,我们将得到如下内容:

    A procedural implementation

    程序执行

    In regular languages, we would get the data set and loop on values to set results into variables then display these results. This is what is done in following T-SQL statement.

    在常规语言中,我们将获取数据集并循环使用值以将结果设置为变量,然后显示这些结果。 这是在下面的T-SQL语句中完成的。

     
    -- To display some timing info:
    SELECT CONVERT(VARCHAR(32),GETDATE(),121) as StartTimeStamp ;
    DECLARE intValues CURSOR LOCAL 
    FOR
        SELECT * FROM #Example1
    ;
     
    DECLARE @TotalVals INT = 0;
    DECLARE @MinValue  INT;
    DECLARE @MaxVal    INT;
    DECLARE @CurVal    INT;
     
    OPEN intValues;
     
    -- init
    FETCH NEXT FROM intValues INTO @CurVal;
    SET @MinValue = @CurVal;
    SET @MaxVal   = @CurVal;
     
    WHILE(@@FETCH_STATUS = 0)
    BEGIN
        SET @TotalVals = @TotalVals + @CurVal;
        SET @MinValue  = CASE WHEN @MinValue > @CurVal THEN @CurVal ELSE @MinValue END;
        SET @MaxVal    = CASE WHEN @MaxVal   < @CurVal THEN @CurVal ELSE @MaxVal END;
     
    	-- Carry on the loop
    	    FETCH NEXT FROM intValues INTO @CurVal;
    END;
     
    CLOSE intValues;
     
    -- Display results
    SELECT 
        @TotalVals as SumOfValues,
        @MinValue  as MinValue,
        @MaxVal    as MaxValue
    ;
     
    -- To display some timing info:
    SELECT CONVERT(VARCHAR(32),GETDATE(),121) as EndTimeStamp ;
     
    

    The results should look like as follows.

    结果应如下所示。

    We can see that this code took 3 ms to run and provide its results. If we want to have a look on timed and IO statistics, we might run the following statement:

    我们可以看到这段代码花了3毫秒来运行并提供结果。 如果要查看定时和IO统计信息,可以运行以下语句:

     
    set statistics io on
    set statistics time on
     
    

    We won’t list all the output when running again the code that implements our example, but we will focus on some points that are taken out of this output. As you will see when you execute the code, there is a lot of stuff that is performed by SQL Server.

    当再次运行实现示例的代码时,我们不会列出所有输出,但是我们将重点介绍从该输出中提取的一些要点。 正如您将在执行代码时看到的那样,SQL Server执行了很多工作。

    First of all, SQL Server had to use CPU time to parse and compile this code.

    首先,SQL Server必须使用CPU时间来解析和编译此代码。

    Then, we see that, as we use a cursor, SQL Server creates a Worktable that will be scanned during execution.

    于是,我们看到,当我们使用游标,SQL Server创建一个工作台 ,将在执行过程中被扫描。

    Alternately, we could have used another implementation that consists in replacing cursor usages by the following query:

    或者,我们可以使用另一种实现,包括通过以下查询替换游标用法:

     
    SELECT TOP 1 
        @CurVal  = ValueInt
    FROM #Example1
    WHERE ValueInt > @ CurVal
     
    

    But this won’t produce the good value for sum if table #Example1 contains multiple occurrences of a value.

    但是,如果表#Example1包含多次出现的值,则这不会产生合计的好的值。

    Set-based implementation

    基于集合的实现

    Now, let’s do it using a set-based approach and aggregate functions:

    现在,让我们使用基于集合的方法和聚合函数来完成此操作:

     
    SELECT CONVERT(VARCHAR(32),GETDATE(),121) as StartTimeStamp ;
     
    select 
        SUM(ValueInt) as SumOfValues,
        MIN(ValueInt) as MinValue,
        MAX(ValueInt) as MaxValue
    FROM 
        #Example1
    ;
     
    SELECT CONVERT(VARCHAR(32),GETDATE(),121) as EndTimeStamp ;
     
    

    This results to something like following screen capture:

    这导致如下屏幕截图所示:

    Results comparison

    结果比较

    And let’s compare time and IO statistics:

    让我们比较时间和IO统计信息:

    When comparing screenshots, we see that the actual execution time is 3 times higher in the procedural version than in set-based approach. This can be explained when we take a look at the number of operations performed by SQL Server in procedural version to produce the exact same results as in set-based version.

    在比较屏幕截图时,我们发现过程版本的实际执行时间比基于集合的方法的执行时间长3倍。 当我们查看过程版本中SQL Server执行的操作数以产生与基于集的版本完全相同的结果时,可以解释这一点。

    To get a better overview of performance, we could generate a bigger table than with just ten rows and compare timing and resources consumption for both implementations provided above.

    为了更好地了解性能,我们可以生成比只有十行的表更大的表,并比较上述两种实现的时序和资源消耗。

    Cleanups

    清理工作

    This ends the example and following statement will clean the temporary table we created:

    到此示例结束,以下语句将清除我们创建的临时表:

     
    DROP TABLE #Example1
     
    

    结论 (Conclusion)

    This article provides us further reasons to get interested in set-based programming:

    本文为我们提供了更多对基于集合的编程产生兴趣的原因:

    • It’s concise and easier to read;

      简洁明了,易于阅读;
    • It avoids unnecessary resource consumption, so looks promising in regards to performance. We can see in this simple example that procedural version leads to worktable creation and a lot more I/O and CPU operations than in set-based version.

      它避免了不必要的资源消耗,因此在性能方面看起来很有希望。 我们可以在这个简单的示例中看到,与基于集合的版本相比,过程版本可以导致工作表的创建以及更多的I / O和CPU操作。

    Now, let’s dive into real set based programming techniques and build solutions that can be very helpful!

    现在,让我们深入研究基于实际集的编程技术,并构建可能非常有用的解决方案!

    进一步阅读 (Further readings)

    As explained in the introduction, this article is part of a series of article. Next article will consider the concept of “set” and provide an overview of the implementation of this concept in T-SQL.

    如引言中所述,本文是一系列文章的一部分。 下一篇文章将考虑“集合”的概念,并概述该概念在T-SQL中的实现。

    Next articles in this series:

    本系列的下一篇文章:

    翻译自: https://www.sqlshack.com/introduction-set-based-vs-procedural-programming-approaches-t-sql/

    sql编程接收一个集合

    展开全文
  • But before that, there is another party arose recently, the 'MengMengDa' party, everyone in this party feel everything is 'MengMengDa' and acts like a 'MengMengDa' guy. While they are very pleased ...
  • 今天在做开发时遇到一个需求,要在一个集合list里面,查询一下是否含"mysql"的字符串,类似于sql语句中的like 二.问题分析: 处理集合问题,我首先想到了java8的stream,但是list.stream().filter貌似处理不了复杂...

    一.问题描述:

         今天在做开发时遇到一个需求,要在一个集合list里面,查询一下是否含"mysql"的字符串,类似于sql语句中的like

    二.问题分析:

          处理集合问题,我首先想到了java8的stream,但是list.stream().filter貌似处理不了复杂的逻辑,只得放弃,后面又在网上搜寻了一下,发现大佬们提供的方法不错,直接放到工具类留作后面用。

    三.问题解决:

    public class SearchUtil {
    
    
        public List search(String name,List list){
            List results = new ArrayList();
            Pattern pattern = Pattern.compile(name);
            for(int i=0; i < list.size(); i++){
                Matcher matcher = pattern.matcher(list.get(i).toString());
                if(matcher.find()){
                    results.add(list.get(i));
                }
            }
            return results;
        }
    }
    
    
    
    //上面那个是大小写敏感的,如果要求大小写不敏感,改成:
    //Pattern pattern = Pattern.compile(name,Pattern.CASE_INSENSITIVE);

     

           

    展开全文
  • Now the code below I am getting the results needed back since I am using Laravel eagerloading to get transactions with their products like so: <pre><code> /** * Display a listing of the resource. ...
  • But before that, there is another party arose recently, the 'MengMengDa' party, everyone in this party feel everything is 'MengMengDa' and acts like a 'MengMengDa' guy. While they are very pleased ...
  • Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below. Example 1: Input: ["Hello", "Alaska", ...
  • <p>I've got an collection: <pre><code>$collection1 = [ 'file1', 'file2' ]; </code></pre> <p>I want to add ... I don't know why this is not working out-of-the-box like in javascript. :/ </div>
  • <p>What i want to do is this: i have to get some data from a database and i would like to store records of two tables in one property. To get data from a table and store it in a property i do this: ...
  • 一个表,总记录数是1000条,现在有一条查询语句: #查询语句1 #找出表中id中含有‘A’或‘B’或‘C’的字段 select * from table1 where id like '%A%' or id like '%B%' or id like '%C%' ; #成功查出300条 嗯...
  • <p>And what I would like to have... <pre><code>foreach($this->deliveryContainers() as $row){ $row->id; } </code></pre> <p>Is there any way to push the eager loaded relationship up a level (if...
  • Redis是一个开源的,底层用c语言编写的,遵守BSD协议,支持网络的key-value存储的数据库..它提供了丰富的数据结构:所存储的值可以是String(字符串) , Hash(哈希) , List(链表) , set(集合) , zset(有序集合); 1.2BSD...
  • <p>Is this possible adding another field in Product like category, and an under the category there are another fields like adding category_name and category_date? and how can I generate that document?...
  • For example I coould use max() or min() on $filtered like this: <pre><code>$max_brand_id = $filtered->max('item_brand_id'); </code></pre> <p>It doesn't make any sense to find the max id in this ...
  • 发现这样的话每次item值都会是list最后一个元素。 解决方法: 把 #{item} 改成 ${item} ps. 改成 ${item} 的话又要考虑sql注入问题,于是最后没有用bind标签,用了 like '%'||#{param}||'%'
  • <p>In my <strong>Profile...<p>It isn't supposed that dynamic propertis execute the query right away like a shortcut of ->lease()->get()? Why it gives different formatted results? </div>
  • 然后查询数据库中记录在第一个参数id数组中的并且姓名是模糊搜索的并且类型是直接相等于的。 注: 博客:https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程序猿 获取编程相关电子书、教程推送与免费...
  • <p>I have some code like following, <pre><code>$query = array("vid"=>"just_a_video_key_and_can_be_any_string"); $set = array("$set" => array("attr" => "attr_value")); $cursor = $collection-&...
  • <p>Here is what the ObjectCollection looks like: <pre><code>ObjectCollection Object ( [line_items_array:ObjectCollection:private] => Array ( [0] => LineItem Object ( [item:LineItem:private] =&...
  • <p>I'm new to GOLANG - I would like to reduce the complexity of the handlers in my GO API. I'm coming from a Node.js background! <p>At the moment a route handler looks like this: <pre><code>func ...
  • Beside other services, ACM helps companies to clearly state their “corporate identity”, which includes company logo but also other signs, like trademarks. One of such companies is Internet Building ...
  • 设计数据结构完成在一个文档集合的存储,并构造算法实现其内容的查询。该设计包括三个部分: ① 应用数据结构完成文档集合的内容(基于单词的)存储,并为下一步的查询建立索引。 ② 就单个单词的查询请求,设计...
  • Only by one line code,and all TextView、Button、ImageView and others support view will show text border、color attr in top of View like gif demo. An introductory article written in Chinese 关于 ...
  • The root form is created like this <pre><code>$form = $factory->createBuilder("form", $this->userData); </code></pre> <p>The yml will have an option to define a collection field as well. The...
  • show VARIABLES like 'max_allowed_packet' ,如果数据太多,就将大集合List分为多集合,分多次批量插入吧。 附上源码 import com.duotin.util.beans.SubListView; import java.util.ArrayList; ...
  • Python---集合set

    2018-03-16 11:12:21
    set:对一个列表做set可得到一个集合。#set定义 like_Chinese=['Sun Da','Li Wei','Meng Dawei','He Ning','Xiao Bei'] like_English=['Bei Fang','Xiao Bei','Deng Deng','Xiao Hua'] like_Chinese=set(like_...
  • python 集合 set

    2014-11-21 13:54:00
    python的set和其他语言类似,是一个无序不重复元素集,基本...作为一个无序的集合,sets不记录元素位置或者插入点。因此,sets不支持indexing,slicing,或其它类序列(sequence-like)的操作。 set 的创建 ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 431
精华内容 172
关键字:

like一个集合