课程: SQL: Data Reporting and Analysis

今天就学习课程吧!

今天就开通帐号,24,600 门业界名师课程任您挑!

Use variables

Use variables

- [Instructor] Now we're going to look at variables. A variable is a user defined keyword that's used to store data and that data might just be a number or a piece of text, a date, but it could also be a whole result set from a query. So with variables there are two obvious ways that you could use them, one is as a filter which is what we're going to look at first. And then the other way is to store results into a variable with select into, and the reason, looking first at the using a variable as a filter, the reason you would want to use a variable is if you've got a particularly long query and you are making reference to an ID say, which is liable to change and perhaps you're making reference to it multiple times then with a variable, you can just update the variable in one place at the top of your code, nice and neat, and you are done. You don't have to go sifting through your code. So in MySQL, to declare a variable…

内容