473,385 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 32827
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
6
by: BigDadyWeaver | last post by:
I am using the following code in asp to define a unique and unpredictable record ID in Access. <% 'GENERATE UNIQUE ID Function genguid() Dim Guid guid =...
4
by: shumaker | last post by:
I'm wondering how/why this query works. Trying to get my head wrapped around SQL. Basically the Query deletes from the Import table all records that are already in FooStrings so that when I do an...
8
by: dlx_son | last post by:
Here is the code so far <form name="thisform"> <h3>Enter time to add to or subtract from:</h3> (If not entered, current time will be used)<br> Day: <input name="d1" alt="Day of month"...
2
by: GIS Analyst | last post by:
Hi to all I wish to be able to have a standard select statement which has additional fields added to it at run-time based on supplied parameter(s). ie declare @theTest1 nvarchar(10) set...
9
by: Downstreamer | last post by:
Design is as follows: A form for the user to input criteria to be used as the where part of the report's recordsource. This includes a multiselect list box as part of the criteria selection. ...
10
by: SueB | last post by:
I currently have a 'mail-merge' process in my Access db project. It generates custom filled out Award Certificates based on an SQL SELECT statement in a VBA routine invoked by clicking on a...
12
by: Charles Astwood | last post by:
Hi, just starting out working my way round C Sharp and aspx. Used to write all my sites in asp and just need a few pointers in how to display data. I have made a connection to my SQL2000...
8
by: Remington | last post by:
I am using windows 2000pro with access 2000. I am trying to make a database for our HR department, that would allow our HR Director to type in an employee's ID number into a form and then select...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.