Available online at www.sciencedirect.com Available online at www.sciencedirect.com
Procedia Engineering
Procedia Engineering 00 (2011) 000–000 Procedia Engineering 24 (2011) 340 – 344 www.elsevier.com/locate/procedia
2011 International Conference on Advances in Engineering
A Study on Database Fuzzy Query Method in SQL ZHANG Peng a* Department of Computer Foundation Studies,Shenyang Institute of Engineering,Shenyang,Liaoning, 110136 China
Abstract The previous work analyzes its simplicity, inquires the multi-relational query, inquires composite inquires, sub-query etc, so as to solve the problem of the influence of fuzzy to some extent. However, logical connection always or Zadeh Based on fuzzy logic, this paper introduces the fuzzy theory and the relationship of the weight to the extended fuzzy query. This kind of fuzzy inquires the solved here through the fuzzy theory and the function of the SQL combination, which will improve the fuzzy inquiry system, so that the query will be more effective.
© 2011 Published by Elsevier Ltd. Selection and/or peer-review under responsibility of ICAE2011. Keywords: Databse fuzzy query, SQL, fuzzy thory
1. Introduction The fuzzy theory which was put forward by Zadeh in 1965 has been used in every field. Experts of the fuzzy inquires field can help extend fuzzy inquiry the fuzzy set. In general, the fuzzy inquiry in database management system is mainly based on two aspects: fuzzy database query and fuzzy inquiry based on classical brittle database. What is talked about here belongs to the latter evolution process. Through the use of "vagueness, impreciseness" inquires the database will be more flexible, which is adapted to the nature and to the state of mind. Generally speaking, in natural language SQL query can be divided into the following items: (1) numerical fuzzy value; (2) the operation of the modified fuzzy relations; (3) quantification fuzzy language; (5) weight. All the above almost involve natural language inquires appearing in ceremony. Now, the fuzzy inquiry in SQL mainly focuses on (1) and (2) from home and abroad. [1] [2] did a great job in simple fuzzy items, items and composition complex fuzzy control. Fuzzy project put forward the fuzzy inquires the transformation method of SQL query regularly help-cuts α. 2. Fuzzy query with weights based on fuzzy logic conjunctions
* Corresponding author. Tel.: E-mail address:
[email protected]
1877-7058 © 2011 Published by Elsevier Ltd. doi:10.1016/j.proeng.2011.11.2653
; fax:.
ZHANG / Procedia – 344 ZHANGPeng Peng/ ProcediaEngineering Engineering2400(2011) (2011)340 000–000
2
Fuzzy linguistic quantifies are introduced here as logic conjunctions instead of AND or OR. Through calculation of membership, threshold and α -cuts , this paper will deal with Fuzzy queries with weights based on fuzzy logic conjunctions and give the result sets according to matching degree. Generally, fuzzy SQL query can be expressed as: SELECT attributes FROM sourceTableName WHERE condition1 [-]… [-]conditionn WITH α attributes: fields of relations in database; sourceTableName: single or multi-relations for retrieving records; condition1… conditionn: conditions that should be satisfied to some extend (it is known as predicates in ANSI / ISO), which can be simple, complex or composed fuzzy predicates; α : threshold;[]:connection relation between different conditions. As suggested by Zadeh, there are two kinds of quantifies in natural language: (1) absolute quantifies: at least two, about two and etc, which can be represented as fuzzy subsets of the nonnegative numbers (2) relative quantifies: most, at least, and etc,which are represented as fuzzy subsets of the unit interval. Therefore where clause in SQL can be expressed as follows: ( condition1[-]…[-]conditionn ) is Q1(absolute quantifies) (condition1[-]…[-]conditionn ) is Q2(relative quantifies); In text retrieval, weights are used to express importance of different conditions. Aw is represented as the query connected with OR, while Aw is represented as the query connected with AND. Here, fuzzy set A represents a query; w is a value between 0 and 1 used to represent the importance of different conditions; the larger w is, the more important A is. w = 0 means A is non-functional; w = 1 means A is full-functional. w For all the texts: Aw = w * A , A = 1 − w *(1 − A) ,*can be any T operator, so there is[3]:
Aw = T ( w, A) , Aw = 1 − t ( w,1 − A) Here, we choose T ( x, y ) = min( x, y ) Aw = min( w, A) , Aw = max(1 − w, A)
This T-operator, in essence, is qualitative; it can be defined in a discrete and orderly possibility scale [4]. Therefore, weights in SQL query are defined as the following. Definition: Membership degree of attribute a Tuple t to A is represented as follows:
u Aw (t , a) = min( w, u A (t , a))
u Aw (t , a) = max(1 − w, u A (t , a ))
Then we can gain the membership degree of attributes involved with weights, therefore do some study on fuzzy queries with weights based on fuzzy logic conjunctions. When Fuzzy linguistic quantifies and weights are introduced, more flexible SQL query can be expressed as: SELECT attibutes FROM sourceTableName WHERE (condition1,…,conditionn) is Q1 [(condition1…,conditionn) is Q2] WEIGHT weight1, weight2,…,weightn WITH α1 , α 2 ,α n FOR β WEIGHT: importance defined by user; WITH: thresholds of different predicates, FOR: defined here as threshold of fuzzy linguistic quantifies; α1 , α 2 ,α n β can be precise or fuzzy items. When Q1, Q2=all
or any, the query will be translated to traditional query connected with AND or OR. There are many
341
342
ZHANG Peng / Procedia Engineering 24 (2011) 340 – 344 ZHANG Peng/ Procedia Engineering 00 (2011) 000–000
different methods to define membership functions (e.g. young, tall and etc.), Here, we take membership functions of predicates as: 1 2 u young ( x ) = x − 25 1 1 + 1 0
u
ta ll
1 (x) = 1
x ≤ 25
x > 25 x ≥ 190
x − 190 1 + 10
1 u s a la r y − h ig h ( x ) = x 6 0 0 0 x 0 .5 u m o st ( x ) = 1
2
x < 190
x >= 6000 0 < x < 6000
0 < x ≤ 0 .5 x > 0 .5
Query: searching Emp_Id, name, Age, Height and Salary of employees in the relation “Employees” that meets: most of conditions “young, tall, salary is high” are true. Weights are given as: Age (0.8), Height (0.5), Salary (0.6); Thresholds: Age (0.7), Height (0.4), Salary (0.5); matching degree (0.6). Then we make SQL query as: SELECT Emp_Id, name, Age, Height, Salary FROM Employees WHERE (Age is young, Height is tall, Salary is high) is most WEIGHT 0.8, 0.5, 0.6 WITH 0.7, 0.4, 0.5 FOR 0.6 Through usage of positive method, it will get membership degree of attributes, and then gain the results according to matching degree through combination of SQL functions and Zadeh’s Computational Approach. All the relative Tables in the process of computation are as follows: Table 1: basic relation; Table 2: initial membership degree of attributes; Table 3: membership degree of attributes combined with weights. Table 1. Employees
Emp_Id 2001 2002 2003 2004 2005 2006 2007 2008 2009
name Wang Peng Zhang Fei Liu Fei Zhang Yu Su Yun Yan Li Wu Lan Zhang Li Li Su
Age 26 33 39 28 25 40 22 31 20
Height (cm) 172 183 170 177 183 175 185 165 173
Salary 8000 3500 4700 2900 3500 6000 4900 4200 4800
Through the help of matching degree of young, tall, salary-high with weights and SQL functions, (when u ' youngy >= 0.7,1, NULL ); (when u 'tall >= 0.4,1, NULL ); (when
u 'salary >= 0.5,1, NULL ); Table 2 and Table 3 will be obtained:
3
343
ZHANG / Procedia – 344 ZHANGPeng Peng/ ProcediaEngineering Engineering2400(2011) (2011)340 000–000
4
Table 2. Initial membership degree of Age, Height, Salary of each tuple
Emp_Id
u young
utall
usalary − high
2001 2002 2003 2004 2005 2006 2007 2008 2009
0.961 0.281 0.113 0.735 1 0.1 1 0.410 1
0.236 0.552 0.2 0.372 0.671 0.308 0.8 0.138 0.257
1.0 0.5833 0.7833 0.4833 0.5833 1.0 0.8167 0.8667 0.8
Table 3. Membership degree of Age, Height, Salary combined with weights
Emp_Id
u ' young
u 'salary − high
u 'tall
u
2001 0.8(1) 0.236(NULL) 0.6(1) 0.667 2002 0.281(NULL) 0.5(1) 0.5833(1) 0.667 2003 0.113(NULL) 0.2(NULL) 0.6(1) 0.333 2004 0.735(1) 0.372(NULL) 0.4833(NULL) 0.333 2005 0.8(1) 0.5(1) 0.5833(1) 1.000 2006 0.1(NULL) 0.308(NULL) 0.6(1) 0.333 2007 0.8(1) 0.5(1) 0.6(1) 1.000 2008 0.410(NULL) 0.138(NULL) 0.6(1) 0.333 2009 0.8(1) 0.257(NULL) 0.6(1) 0.667 Take use of membership function of “most”, Table 4 will be gained according to matching degree. Table 4. The result sets
Emp_Id
name
Age
Height
Salary
2005 Su Yun 25 183 3500 2007 Wu Lan 22 185 4900 2001 Wang Peng 26 172 8000 2002 Zhang Fei 33 183 3500 2009 Li Su 20 173 4800 ( umost is the matching degree of every tuple that satisfying the query).
umost 1.000 1.000 0.667 0.667 0.667
Here, we just give a simple example to represent the basic principle of fuzzy SQL queries with weights based on fuzzy logic conjunctions. Obviously, this strategy can be extended to more fuzzy queries and also can be extended to web retrieval. 3. Conclusion Based on the fuzzy SQL inquires and the study of the fuzzy theory, the logic of fuzzy language zadeh conjunction quantified, not the traditional OR. And for this kind of fuzzy inquires the solution is to use the fuzzy theory, combining with the SQL function and positive or reverse modeling, nested inquires fuzzy logic connections given below will further research involving gathered function .
344
ZHANG Peng / Procedia Engineering 24 (2011) 340 – 344 ZHANG Peng/ Procedia Engineering 00 (2011) 000–000
References [1] Zhou Hong, Xu Xiao-Bang, Wang Li-yu, “The Design of Database Query Tool Based on the Fuzzy Algorithm”, Application Research of Computers, Institute of Computer Reseach,Sichuan Pro. , 2010. 18(5), pp.15-17. [2]Zhu Rong, “Research of Query Technique Based on Fuzzy Theory”,Application Research of Computers, Institute of Computer Reseach,Sichuan Pro.,2010. 20(5), pp.8-29. [3]Shyi-Ming Chen, Woei-Tzy Jong,”Fuzzy Query Translation for Relational Database Systems”, IEEE Transaction on System and Cybernetics, USA 1997. 27(4), pp.714-720. [4]Shyi-Ming,Yun_Shyang Lin,”A new method for query processing in relational database systems”, Cybernetics and System, 2002.33(1),pp.447-482. [5]Ying-Chao Zhang, Yi-Fei Chen, Xiao-Ling Ye,”Weighted Fuzzy Queries in Relational DataBase”,Lecture Notes in Computer Science,2005.3614,pp.430-440.
5