Mysql uses median to temporarily store values

Source: Internet
Author: User


Mysql uses the median to temporarily store the value. When querying data, mysql sometimes uses the following statement to find a value. At this time, you may consider how to store this value, there are two methods to achieve the goal: 1. Use custom values. II. Use an intermediate table. The following describes how to call these two methods: www.2cto.com 1. how to save a value of a table to a custom variable using memory SQL code # define @ amax_price as a constant value mysql> set @ amax_price = (select max (FScoreCount) from Tbl_User); Query OK, 0 rows affected (0.00 sec) mysql> select * from Tbl_User where FScoreCount = @ amax_price; + --------- + ----------- + ------- + ------ + ------------- + ------------ + -------------- + -------- + --------- + ----------- + ------------ -- + ------- + --------- + Response + ---------- + response + ------------ --------- + response + ------- + | FUserId | FQQ | FNick | FPwd | FScoreCount | FVoteCount | FInviteCount | FBType | FLType | FEnable | FValue1 | FValue2 | FValue3 | FValue4 | FValue 5 | FValue6 | FTime | FDate | FIp | FLastLoginT ime | FLastLoginDate | FMemo | + --------- + ------- + ------ + ----- -------- + ------------ + Certificate + -------- + --------- + certificate + ------- + --------- + certificate + ---------- + certificate + ------------ ----------- + certificate + ------- + | 1 | 455342107 | 22 | 0 | 2 | 0 | 0 | 0 | 1 | 0 | 2011-08-15_3 | 2011-0 8-10_2 | 10:02:40 | 2011-08-10 | 192.168.1.34 | 14:30:18 | 20 11-08-16 | + --------- + ----------- + ------- + ------ + upper + ------------ + -------------- + -------- + --------- + --------- + --------------------- + ------------ + -------------- + ------------ --------- + ---------------- + ------- + 2. how to save a value of a table to the SQL code of the temporary table # locate all values in the Tbl_User table mysql> select FQQ, FScoreCount from Tbl_User; + ----------- + ---------- --- + | FQQ | FScoreCount | + ----------- + | 455342107 | 22 | 24222 | 0 | 345333 | 5 | 664444 | 5 | 234324 | 0 | 137543511 | 5 | 519422206 | 5 | 234222 | 0 | 14234 | 5 | 1242354 | 5 | 111565 | 5 | 342323 | 0 | 234322 | 0 | 543244 | 0 | + ----------- + ------------- + 14 rows in set (0.00 sec) # store the maximum value on the temporary table tmp mysql> create table tmp select max (FScoreCount) as max_s Core from Tbl_User; Query OK, 1 row affected (0.05 sec) Records: 1 Duplicates: 0 Warnings: 0 # locate the temporary table structure mysql> select * from tmp; + ----------- + | max_score | + ----------- + | 22 | + ----------- + 1 row in set (0.00 sec) mysql> show tables; + comment + | tables_in_db_nissansunny_20151108 | + ---------------------------------- + | Tbl_Code | Tbl_Comment | Tbl_File | Tbl_Invite History | Tbl_LotteryCount | statistics | Tbl_QQshow | Tbl_Score | statistics | Tbl_User | Tbl_UserAward | Tbl_UserProfile | tmp | + statistics + 14 rows in set (0.00 sec) the two methods are different: the custom variables use the memory, and the temporary tables use the database space .. Haha, we recommend that you use a temporary table for a large data volume...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.