Create constant value in subquery : Sub query « Select Clause « SQL / MySQL






Create constant value in subquery

       
mysql>
mysql> SELECT   NUMBER AS SQUARE, ROUND(SQRT(NUMBER)) AS BASIS
    -> FROM    (SELECT    CAST(CONCAT(DIGIT1.DIGIT,
    ->                    CONCAT(DIGIT2.DIGIT,
    ->                    DIGIT3.DIGIT)) AS UNSIGNED INTEGER)
    ->                    AS NUMBER
    ->          FROM     (SELECT '0' AS DIGIT UNION SELECT '1' UNION
    ->                    SELECT '2' UNION SELECT '3' UNION
    ->                    SELECT '8' UNION SELECT '9') AS DIGIT1,
    ->                   (SELECT '0' AS DIGIT UNION SELECT '1' UNION
    ->                    SELECT '2' UNION SELECT '3' UNION
    ->                    SELECT '8' UNION SELECT '9') AS DIGIT2,
    ->                   (SELECT '0' AS DIGIT UNION SELECT '1' UNION
    ->                    SELECT '2' UNION SELECT '3' UNION
    ->                    SELECT '8' UNION SELECT '9') AS DIGIT3)
    ->                    AS NUMBERS
    -> WHERE    SQRT(NUMBER) = ROUND(SQRT(NUMBER))
    -> ORDER BY NUMBER;
+--------+-------+
| SQUARE | BASIS |
+--------+-------+
|      0 |     0 |
|      1 |     1 |
|      9 |     3 |
|     81 |     9 |
|    100 |    10 |
|    121 |    11 |
|    289 |    17 |
|    900 |    30 |
+--------+-------+
8 rows in set (0.00 sec)

mysql>

   
    
    
    
    
    
    
  








Related examples in the same category

1.Subqueries As Calculated Columns: Simple Subqueries
2.Subqueries in the WHERE Clause 2
3.Subqueries That Return Multiple Results
4.Sub queries
5.Sub query with string concatenate
6.Sub query with not equal and order
7.Sub query with calculation
8.Update command with sub query
9.Delete command with sub query
10.SubSELECTs Syntax Variants
11.Uses a subquery to return an AuthID value
12.Use a not equal (<>) comparison operator in the WHERE clause to introduce the subquery
13.Subquery uses an aggregate function to arrive at a value that the outer statement can use
14.Nested subquery
15.Four-level nested subquery with alias
16.Nested subquery and where clause
17.Minus value from subquery
18.Subquery and equals operator(ERROR 1242 (21000): Subquery returns more than 1 row)
19.Row values and subquery
20.Nested three level subquery
21.Greater than the result of subquery
22.Equals to the result of subquery
23.Row values comparison for subquery
24.Select from the result of subquery
25.Value calculation of subquery
26.Subquery as a table
27.Alias subquery
28.Calculation in subquery
29.Using function with result from subquery
30.Calculation in subquery and use the result from outside
31.Equals operator with subquery
32.Less than and subquery(ERROR 1242 (21000): Subquery returns more than 1 row)
33.Less than data type value from subquery
34.<=> and subquery
35.Less than two values in subquery
36.Greater than two values in subquery
37.Get substring for a value from subquery
38.Mix constant value and subquery
39.Using the value from subquery with in operator
40.Pair value within in operator and subquery
41.In a list of value from subquery
42.In operator and subquery
43.Nested subquery and in operator
44.Not in and subquery
45.Between...and opertor and subquery
46.Count value in subquery
47.Add up count value from subquery
48.From a subquery
49.Aggregate function in subquery
50.Having clause with subquery
51.Count and subquery in Having clause
52.Subquery with having clause
53.Order by value from subquery
54.Subquery with limit clause
55.Insert statement with subquery
56.Use a derived table.
57.Searching for Titles Without Authors
58.Compare to aggregate function
59.Data calculation inside in operator
60.COMPARISON OPERATORS WITH SUBQUERIES
61.Select from three subqueries
62.Select from two subqueries
63.Row value comparison with select statement
64.Compare two data type value together
65.Nested subqueries
66.Two USING clauses, rather than ON clauses
67.Finding people who didn't send mail to themselves