sql语句,高手指点一下

来源:百度知道 编辑:UC知道 时间:2024/05/16 07:14:52
1. userid username
1 a
2 b
3 c
4 a
5 c
...... ......
用sql语句列印重复的username.
2. goodsid goodsname goodscost
1 a 87
2 a 67
3 a 78
4 b 91
5 b 98
6 b 34
...... ...... ......
用sql语句列印每种货物的名字和最高价格.(goodsname,goodsmaxcost)

select username
from table_name
group by username
having count(*)>1

select goodsname, max(goodscost) as goodsmaxcost
from table_name
group by goodsname

goodsname,goodsmaxcost
a 87
b 98
……
没给请条件,最好把查询所用到的表给出来
我根本不知道goodsmaxcost这列有没有在表里面

select distinct(username)
from table_name

select goodsname,max(goodscost) 'goodsmaxcost'
form table_name
(这个就感觉有什么问题,不能满足你的要求)