How do I get rhe right syntax for searching a string in a database table?
List the state descriptions that start with "NEW" and the count of the
employers located in that state. Be sure to list all of those states that
start with "NEW" even if the count is zero. Make sure your column headings
match what is shown below.
+---------------+---------------------+
| Description | Number of Companies |
+---------------+---------------------+
| NEW HAMPSHIRE | 0 |
| NEW JERSEY | 1 |
| NEW MEXICO | 0 |
| NEW YORK | 13 |
+---------------+---------------------+
4 rows in set (0.00 sec)
For this question I used:
SELECT state.description, COUNT(*) "Number of Commpanies"
FROM employer
WHERE SUBSTR(state.description, 1, INSTR(state.description, 'NEW')-1) AS
"Number of Companies";
ERROR:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual
that
corresponds to your MySQL server version for the right syntax to use near
'AS "N
umber of Companies"' at line 3
Why am I getting this and what is the right syntax. First of all, I'm not
sure if I'm following the question correctly. The table as follows:
mysql> DESCRIBE state;
+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| statecode | char(2) | | PRI | | |
| description | varchar(30) | | | | |
+-------------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec) mysql>
mysql>SELECT * FROM employer
| companyname | division | address
| city | statecode | zipcode |
| Acme Information Source | Customer Support | 132 Commerical Way
| Cleveland | OH | 44234 |
| Ajax Software, Inc. | RandD | 2421 West Industrial
Way | Berkeley | CA | 94710 |
| Ajax Software, Inc. | Production | 2421 West Industrial
Way | Berkeley | CA | 94710 |
No comments:
Post a Comment