作者JoeHorn (每天都在公司玩OLG)
看板Database
标题Re: [问题] 请问该怎麽下以下的语法
时间Wed Jun 4 01:12:55 2008
又一篇没说 DBMS 的。
※ 引述《lemarulie (另一个我)》之铭言:
: 目前我的资料表有ll mm id 和money四个栏位
: id是由使用者自行输入
: 若使用者将在前端将id输入後
: 程式会将ll mm这两笔资料抓出来 同时 选出来的资料中money是最多的
: 请问要怎麽下呢?
: 目前我的想法是这样,可是一直有问题(mytest是资料表名称)
: select ll,mm from mytest where id=使用者输入的id
: 那请问money是最多的这个条件要放在哪?
: 目前跑到上面都没什麽问题
: 但是我如果加上
: select ll,mm from mytest where id=使用者输入的id AND money=MAX(money)
: 这时就出问题了
: 请各位高手指点我一下
SELECT `ll`, `mm`
FROM `mytest`
WHERE `id`='使用者输入的id'
ORDER BY `money` DESC LIMIT 1
--
Linux is for people who want to know why it works.
Mac is for people who don't want to know why it works.
DOS is for people who want to know why it does not work.
Windows is for people who don't want to know why it does not work.
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.173.168.11
1F:推 PsMonkey:才刚砍完信就回 po 了,真快 XD 06/04 01:14
2F:→ JoeHorn:乱逛刚好看到~ @_@a 06/04 01:50
3F:推 lemarulie:抱歉没看清楚楚版规....也感谢j大解决了我的问题 06/04 08:34
4F:推 lemarulie:不过加上LIMIT 1之後有错误 我用是是SQL SERVER ^^ 06/04 08:39
5F:推 menjar:SQL Server => select top(1) ..... 06/04 10:05
6F:推 Antzzz:有错误是因为SQL Server是用top而不是limit语法 06/04 12:19