搜索数据表中的项目列表 [英] Search a list of items on a datatable

查看:73
本文介绍了搜索数据表中的项目列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个书籍记录表,我想在数据表中搜索书籍列表.有人可以向我建议查询吗?

表格如下所示

I have a table for book records, I want to search a list of books in the data table. can anyone suggest me the query please?

Table looks like below

DCN varchar(50)
BookName varchar(100)
Author Varchar(100)


这是一条巨大的数据记录,现在我有10个DCN,我想检查这些是否在此表记录中.


It is a huge data record and now I have 10 DCNs with me and I want to check if these are in this table records.

推荐答案

选择计数如何(* ),从myTable那里DCN ="DCN1",然后对每个表执行此操作.或者,您可以选择DCN并进行嵌套查询或使用或语句将其全部列出,然后,如果返回的少于10个,则需要遍历它们以找出缺少的DCN(一次执行一次告诉您马上就可以看到).

我建议如果您真的不知道如何编写查询来检查表中是否有记录,那么您也许应该购买一本关于SQL的书并阅读它.
How about select count (*) from myTable where DCN = "DCN1", then do it for each table. OR you could select the DCNs and do a nested query or use or statements to list them all, then if you get less than 10 back, you need to iterate through them to work out which ones are missing ( doing one at a time tells you that right away, obviously ).

I would suggest if you really didn''t know how to write a query to check if a record is in a table, that you should perhaps buy a book on SQL and read it.


由于您已经拥有DCN,因此可以使用以下SQL查询:

SELECT COUNT(*)
< tablename>
DCN IN( DCN1 DCN2 DCN3 DCN4 DCN5 DCN6 DCN7 DCN8 DCN9 DCN10 );

这将返回记录的计数,这些记录的DCN具有您列出的任何DCN.或者,您可以包括要显示的字段,而不是COUNT(*),后者仅返回计数,而个人认为不是那么有用
Since you already have the DCN''s with you, you can use this SQL query:

SELECT COUNT(*)
FROM <tablename>
WHERE DCN IN (DCN1, DCN2, DCN3, DCN4, DCN5, DCN6, DCN7, DCN8, DCN9, DCN10);

This will return the count of records that has their DCN has any of the DCN''s you listed. Alternatively you can include the fields you want to display instead of COUNT(*) which just returns the count and which personally is not so informative


这篇关于搜索数据表中的项目列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆