Background technology
Along with computing machine utilization universalness, the record of data transfers to and is recorded in electronic media (or file) by being recorded in the Hard copy file gradually, and Various types of data can be recorded in these electronic medias (or file) and converge the whole database that is.The most normal function of using of lane database is data query, and the user can for example inquire about with the SQL instruction, and capture the data that are associated by database by assigning query statement.For instance, with the survey data, comprise that testee's sex, age, hobby, the income and the number of times of seeing a film weekly etc. are stored in the database.The user is as if wondering the film market of age level greater than 20 years old, can learn by assigning simple query statement, for example: Select Movie_Times_Week From Survey--_Inf where age>20, and the user also can be by instructing and computing than complicated query, learn the potential film market total value of above-mentioned age level, the user for example can assign: Select SUM (ICOME) From Survey_Inf where age>20 are taken in total value to learn age level the testee more than 20 years old, and for example assign: SelectSUM (Movie_Times_Week) From Survey_Inf where age>20 learn that age level watches the total degree of film weekly the testee more than 20 years old, and the testee more than 20 years old that will inquire about takes in total value and cuts the amount of money that total degree spent of watching film weekly, and just can obtain above-mentioned potential film market total value.
Yet, desire is brought into play the function of database incisively and vividly, the good and the bad that often depends on the query statement of assigning, and the good and the bad of query statement depends on the understanding of user to database (for example field meaning), and the complexity of the query statement of assigning, for example may be time-consuming with a plurality of better simply SQL instruction acquisition datas with complicated SQL instruction acquisition data, therefore complicated SQL just can be regarded as second-rate query statement.This shows that the manual operation factor may force in the usefulness of collecting with the data of management database and have a greatly reduced quality, and therefore needs a kind of database inquiry system and method that is independent of manual operation, avoid and improve above-mentioned disappearance.
Summary of the invention
Technical matters to be solved by this invention is can produce automatically behind the input inquiry object corresponding query statement, in order in the data base querying data.
For achieving the above object, the present invention reaches by System and method for two aspects, and the disclosed system of the present invention includes: an intelligent memory storehouse, in order to store a plurality of query objects and corresponding query statement thereof; A database is inquired about for the user in order to storage data; And an analysis and consult module, make up in order to the object that produces these query object correspondences, and produce corresponding query statement, thereby export a result set to inquire about this database according to a search algorithm.Wherein, above-mentioned analysis and consult module is more calculated the inquiry composite score of these query statement correspondences, and the query statement of the minimum inquiry composite score correspondence of record is in the intelligent memory storehouse, and will accumulate a result set by the output of database.
The data base query method of the disclosed tool intelligence inquire of the present invention ability includes the following step: at first import at least one query object, to inquire about corresponding at least one query statement; Afterwards, if judge that corresponding query statement is arranged, then according to these query statement Query Databases, to export a result set; Then,, then produce several object combinations, and produce the corresponding query statement of these object combinations in order to Query Database according to a search algorithm according to these query objects if judge do not have corresponding query statement; Then calculate a plurality of inquiry composite scores of these query statement correspondences according to the output of this database; At last, find out minimum inquiry composite score, and write down the query statement of this inquiry composite score correspondence, and the result set of this query statement correspondence of output.
By said system and method as can be known, the present invention is by producing the query statement of query object correspondence, and calculate and write down the less query statement of inquiry cost of these query statement correspondences, and when inquiring about with identical query object backward, be able to take out corresponding query statement automatically and come data query, when avoiding the manual operation database, assign relatively poor benefit or wrong query statement and reduce the utilization benefit of Database Systems.
About detailed features of the present invention and real the work, now cooperate to be shown in the embodiment and be described in detail as follows, its content is enough to make those skilled in the art to understand technology contents of the present invention and implements according to this, and according to the disclosed content of this instructions and graphic, any those skilled in the art can understand purpose and the advantage that the present invention is correlated with easily.
Embodiment
For allow above-mentioned and other purpose of the present invention, feature and advantage can be more apparent and understandable, cited below particularlyly goes out an embodiment, and cooperates appended graphicly, be described in detail below.
The database inquiry system synoptic diagram that Fig. 1 carries for the embodiment of the invention.Please refer to Fig. 1, the database inquiry system of present embodiment (abbreviation system later on) comprises that an intelligent memory storehouse 110 is used for storing the query object of input and the query statement of these query object correspondences; A database 120 is used for storage data to inquire about for the user; An analysis and consult module 130 is used for producing the object combination of query object correspondence, and produces corresponding query statement according to an algorithm, and inquires a result set with these query statements at database 120.In addition, analysis and consult module 130 can calculate corresponding inquiry composite score according to member's number of the result set of required time of each query statement inquiry and passback.The cost of these query statement Query Databases 120 is used in these inquiry composite score representatives.Analysis and consult module 130 can find out these the inquiry composite scores in minimum value (in the present embodiment, there is less inquiry composite score to represent corresponding query statement to inquire more accurate data) with the short time, and the pairing query object of inquiry composite score of this minimum and query statement be stored in the middle of the intelligent memory storehouse, and the user is given in the result set output that inquires.
The preceding paragraph that continues falls, and also comprises an inquiry calculation module 132 and a comparing module 134 in the above-mentioned analysis and consult module 130.Inquiry calculation module 132 is deposited the algorithm of the multiple query statement that calculates the query object correspondence, inquiry calculation module 132 can produce some objects combinations according to the relation of query object by this algorithm, with further according to the query statement of these object combination results correspondences.When analysis and consult module 130 several query statements of generation, and to obtain Query Result behind these query statement Query Databases 120, analysis and consult module 130 can accumulate a result set with these Query Results.At this moment, 134 of comparing module can and produce these results and required time produces corresponding inquiry composite score according to member's number of these result sets, and further judge minimum an inquiry composite score and corresponding query statement thereof, in order to this query statement is recorded in intelligent memory storehouse 110.When the user imported identical query object next time, system did not just need to produce once more corresponding query statement, come data query and can directly extract query statement by the intelligent memory storehouse.
Subsidiary one carries, the intelligent memory storehouse 110 of native system can for example be that a hard disk or a flash memory etc. can be in order to store the media of query object and corresponding query statement, and query statement in the present embodiment, for example be a kind of Structured Query Language (SQL) instruction (Structured Query Language, SQL), any those skilled in the art is when can not limiting its scope at this according to the teaching correct of present embodiment.
The data base query method process flow diagram that Fig. 2 carries for the embodiment of the invention.Please refer to Fig. 2, the data base query method of present embodiment comprises the steps: at first, import at least one query object (step 210), these query objects for example are not to use that the person desires to assign chooses object and scope, rather than for example data base querying instruction such as SQL; At this moment, system can judge whether to have the query statement of these query object correspondences, query statement for example is SQL or other query statement in order to Query Database, if judge and have several corresponding query statements, then inquire about this database, to export a result set (step 220) according to these query statements; If judge and do not have a query statement of correspondence, then produce several objects combinations, and produce the corresponding query statement of these objects combinations in order to Query Database (step 230) according to a search algorithm according to these query objects; Then, calculate the inquiry composite score (step 240) of these query statement correspondences according to the data of database output; At last, find out minimum inquiry composite score, and write down the query statement of this inquiry composite score correspondence, and the result set (step 250) of output query statement correspondence.
Search algorithm in the present embodiment is to produce object combination and corresponding query statement thereof according at least one query object of input with the relation of Database field, and it comprises that step is as follows: whether the database of at first seeking system comprises the query object of input; If judge not comprise these query objects fully, then export an error message, for example: database does not comprise the data that your desire is sought, and please imports once more.Comprise at least one query object if judge, then according to these query objects several forms of database relevance produce the arrangement of object combination, for example import three query objects such as A, B, C according to the form number of relevance respectively do for oneself 5 forms, 1 form, 1 form, this moment, the object combination for example was ABC, representative is just inquired about according to relevance, the relevant information of inquiry A object is inquired about the B object more earlier, inquires about the C object afterwards again; At last, according to the query statement of these object combination results correspondences.
Hold above-mentioned, system is the automatic Query Database of each query statement to produce respectively, and will by database search to the result compile result set for each query statement correspondence, the field that result set comprises is query object field, query statement field, required time field, member's field etc. as a result for example, in order to the project of clear expression user inquiry, several query statements that system produces, search the database required time and by database search to data.In addition, system more can calculate the inquiry composite score of mentioning in step 240.The quality of assigning query statement depend on query time and the data found out what, generally speaking, the user wishes to find out accurate data with the short more time, and accurate more when the query statement that assign, the member's as a result who is found number is few more certainly.For instance, desire is sought the price information of teas drink in merchandising database, if single data of asking as receipts with drink, the number of then finding out of member as a result is too various, even may search the price data of soda.If with teas drink, PET bottle packing and selling spot as queried for items, though find information more accurate, yet increase the time of searching database.The inquiry composite score is exactly the quality that is used for representing with a query statement Query Database, and its account form adds up for the number of member as a result with result set adds the spent time of Query Database.Each query statement all has corresponding inquiry composite score, and the quality of the query statement of less in the present embodiment inquiry composite score correspondence is high more, and the quality of the bigger pairing query statement of inquiry composite score is low more.Comparing module in the analysis and consult module of system can be selected the pairing query statement of minimum inquiry composite score as preferable query statement, and is recorded in the intelligent memory storehouse.
In sum, the present invention stores the query statement of the preferable inquiry quality of tool because of adopting the intelligent memory storehouse, and produce several query statements of query object correspondence automatically and input database inquiry and judge the query statement of the preferable inquiry quality of tool by the analysis and consult module, and then stored, and have following advantage at least:
(1) user only needs the input inquiry project can produce query language automatically.
(2) do not need the form or the field of database are understood in depth, can operate.
(3) system produces the query statement of the higher inquiry quality of tool automatically, avoids using the query statement Query Database of relatively poor benefit and the inquiry benefit that reduces database.
Certainly the present invention also can have other various embodiments; under the situation that does not deviate from spirit of the present invention and essence thereof; being familiar with those of ordinary skill in the art ought can make various corresponding changes and distortion according to the present invention, but these corresponding changes and distortion all should belong to the protection domain of the appended claim of the present invention.