• 使用用户自定义变量

    使用用户自定义变量

    找到价格最高和最低的信息:

    1. mysql> SELECT @min_price:=MIN(price),@max_price:=MAX(price) FROM shop;
    2. mysql> SELECT * FROM shop WHERE price=@min_price OR price=@max_price;
    3. +---------+--------+-------+
    4. | article | dealer | price |
    5. +---------+--------+-------+
    6. | 0003 | D | 1.25 |
    7. | 0004 | D | 19.95 |
    8. +---------+--------+-------+

    原文: https://strongyoung.gitbooks.io/mysql-reference-manual/content/tutorial/common_queries/using_user_defined_varibles.html