469,912 Members | 1,848 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,912 developers. It's quick & easy.

How does one add or subtract two fields in a select statement

I would like to subtract tow fields in table
for example Table1 has fields A, B, C

I wrote the statement as follows

Select A, B, (A-B) as diff from Table1.

MySQL is complaining that there is a syntax error near '-'

thank you
John
Jul 19 '05 #1
3 32011
John wrote:
I would like to subtract tow fields in table
for example Table1 has fields A, B, C

I wrote the statement as follows

Select A, B, (A-B) as diff from Table1.

MySQL is complaining that there is a syntax error near '-'


mysql> create table Table1(A int, B int);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into Table1 values(4,2),(13,4),(8,6);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select A, B, (A-B) as diff from Table1;
+------+------+------+
| A | B | diff |
+------+------+------+
| 4 | 2 | 2 |
| 13 | 4 | 9 |
| 8 | 6 | 2 |
+------+------+------+
3 rows in set (0.00 sec)

mysql> select Version();
+-------------+
| Version() |
+-------------+
| 3.23.49-log |
+-------------+
1 row in set (0.02 sec)

mysql>
Jul 19 '05 #2
John wrote:
I would like to subtract tow fields in table
for example Table1 has fields A, B, C

I wrote the statement as follows

Select A, B, (A-B) as diff from Table1.

MySQL is complaining that there is a syntax error near '-'


mysql> create table Table1(A int, B int);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into Table1 values(4,2),(13,4),(8,6);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select A, B, (A-B) as diff from Table1;
+------+------+------+
| A | B | diff |
+------+------+------+
| 4 | 2 | 2 |
| 13 | 4 | 9 |
| 8 | 6 | 2 |
+------+------+------+
3 rows in set (0.00 sec)

mysql> select Version();
+-------------+
| Version() |
+-------------+
| 3.23.49-log |
+-------------+
1 row in set (0.02 sec)

mysql>
Jul 19 '05 #3
John wrote:
I would like to subtract tow fields in table
for example Table1 has fields A, B, C

I wrote the statement as follows

Select A, B, (A-B) as diff from Table1.

MySQL is complaining that there is a syntax error near '-'


mysql> create table Table1(A int, B int);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into Table1 values(4,2),(13,4),(8,6);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select A, B, (A-B) as diff from Table1;
+------+------+------+
| A | B | diff |
+------+------+------+
| 4 | 2 | 2 |
| 13 | 4 | 9 |
| 8 | 6 | 2 |
+------+------+------+
3 rows in set (0.00 sec)

mysql> select Version();
+-------------+
| Version() |
+-------------+
| 3.23.49-log |
+-------------+
1 row in set (0.02 sec)

mysql>
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by shumaker | last post: by
9 posts views Thread by Downstreamer | last post: by
12 posts views Thread by Charles Astwood | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.