'Using User-Defined Variables'에 해당되는 글 1건

  1. 2011.08.26 Using User-Defined Variables by CEOinIRVINE

Using User-Defined Variables

IT 2011. 8. 26. 08:08

Using User-Defined Variables

You can employ MySQL user variables to remember results without having to store them in temporary variables in the client. (See Section 8.4, “User-Defined Variables”.)

For example, to find the articles with the highest and lowest price you can do this:

mysql> SELECT @min_price:=MIN(price),@max_price:=MAX(price) FROM shop;mysql> SELECT * FROM shop WHERE price=@min_price OR price=@max_price;+---------+--------+-------+| article | dealer | price |+---------+--------+-------+|    0003 | D      |  1.25 ||    0004 | D      | 19.95 |+---------+--------+-------+
Note

It is also possible to store the name of a database object such as a table or a column in a user variable and then to use this variable in an SQL statement; however, this requires the use of a prepared statement. See Section 12.6, “SQL Syntax for Prepared Statements”, for more information.

'IT' 카테고리의 다른 글

AUTO_INCREMENT  (0) 2011.08.26
Calculating Visits Per Day  (0) 2011.08.26
Getting Information About Databases and Tables  (0) 2011.08.26
using More Than one Table  (0) 2011.08.26
Counting Rows  (0) 2011.08.26
Posted by CEOinIRVINE
l