请教各位大侠sql问题

2024-12-12 08:47:13
推荐回答(1个)
回答1:

虽然回答晚了,但希望对你能有所帮助

1.3、SELECT au_fname, au_lname, au_id FROM authors WHERE (au_id LIKE '_____80%')
修改:WHERE substring(au_id,5,2)='80' ;where 语句后不一定非要加(), 我不知道au_id是什么类型的,如果au_id是整数类型,要转换一下,如下:
WHERE substring(cast(au_id as char(30),5,2)='80'

1.4、SELECT titles.*, price AS Expr1 FROM titles WHERE (price > 15)
修改:既然你写了titles.*,那就不用再写price了,因为*代表了所有的字段,建议在select语句中不要用*

2.1、SELECT *, 姓名 AS Expr1, 年龄 AS Expr2, 出生日期 AS Expr3, 工作时间 AS Expr4, 工资 AS Expr5 FROM 职工工资 WHERE (年龄 > 30)
修改:问题同上

2.3、SELECT *, 姓名 AS Expr1, 年龄 AS Expr2, 总收入 AS Expr3 FROM 职工工资 WHERE (总收入 >= 4000)
修改:问题同上

3.1、SELECT *, city AS Expr1 FROM authors WHERE (city = 'OAKLAND')
修改:问题同上

3.2、SELECT COUNT(*) AS Expr1, state, MAX(zip) AS 最大值 FROM authors GROUP BY state
修改:去掉COUNT(*) AS Expr1, 真不明白你为会么一定要求出count(*)的值呢!

3.3、SELECT COUNT(*) AS Expr1, SUM(qty) AS 总量 FROM sales
修改:去掉COUNT(*) AS Expr1,

3.4、SELECT COUNT(*) AS Expr1, AVG(price) AS 平均值 FROM titles WHERE (type = 'BUSINESS')
修改:去掉COUNT(*) AS Expr1,

3.5、SELECT * FROM authors WHERE (NOT (state IN ('CA')))
修改:SELECT * FROM authors WHERE state <>'CA'
或SELECT * FROM authors WHERE state not in('CA')

基本的sql语法,要再看一看。