title: how to use SQL user defined function in snowflake?
body: <p>I am just studying how to use SQL in snowflake. Here is a snapshot:</p>
  
  <p><a href="https://i.stack.imgur.com/8sIzs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8sIzs.png" alt="enter image description here"></a></p>
  
  <p>And this is the code used in here:</p>
  
  <pre><code>use schema SNOWFLAKE_SAMPLE_DATA.TPCH_SF1;
  --use schema SNOWFLAKE_SAMPLE_DATA.TPCH_SF10;
  
  select *
  from LINEITEM
  limit 200
  </code></pre>
  
  <p>You can see the table includes two feilds: L_LINENUMBER, L_QUANTITY. Now I want to try a user defined function, which can do:</p>
  
  <ol>
  <li>use L_LINENUMBER, L_QUANTITY as two parameters transferred into the function,</li>
  <li>calculate L_LINENUMBER1=L_LINENUMBER+1, and L_QUANTITY1=mean(L_QUANTITY).</li>
  <li>join the two new fields (L_LINENUMBER1, L_QUANTITY1) to the original table (LINEITEM)</li>
  </ol>
  
  <p>how to use create function to do this. I have read a lot of examples regarding create function. But I just cannot get the point. Maybe because I am not good at SQL. So, could anyone give me a comprehensive example with all the details?</p>