在查询语句中排序的问
select * from t_seller order by phone,clickTimes我想让有电话并点击次数最多的排前面该如何实现?
请各位大侠帮帮忙. --------------------编程问答-------------------- 不清楚,常结帖 --------------------编程问答-------------------- order by phone ASC,clickTimes DESC --------------------编程问答-------------------- select * from t_seller where phone<>'' and phone<>null order by clickTimes desc --------------------编程问答-------------------- select * from t_seller order by clickTimes desc where t_id in (select t_id from t_seller where phone <> '')
--------------------编程问答-------------------- --------------------编程问答--------------------
这个是正解 --------------------编程问答-------------------- --------------------编程问答--------------------
正解 --------------------编程问答--------------------
指出这位兄弟的一个错误,null不能用=,<,>来判断。
应该是这样:
select * from t_seller
where phone <>'' and phone is not null
order by clickTimes desc
看看这个示例:
declare @t table(id int,test int)--------------------编程问答-------------------- 3楼的SQL 可以这样写 SYBASE
insert @t select 1,null
union all select null,2
union all select 3,null
union all select 4,4
select * from @t
select * from @t where test is not null
select * from @t where test <> null
/*
(所影响的行数为 4 行)
id test
----------- -----------
1 NULL
NULL 2
3 NULL
4 4
(所影响的行数为 4 行)
id test
----------- -----------
NULL 2
4 4
(所影响的行数为 2 行)
id test
----------- -----------
(所影响的行数为 0 行)
*/
select * from t_seller where isnull(phone,'') <> '' order by clickTimes desc --------------------编程问答-------------------- select * from t_seller where phone <> '' order by clickTimes desc --------------------编程问答-------------------- 各位楼主都给了答案,小弟只能学习了.
补充:.NET技术 , C#