查询语句概念模糊了,请大虾指教啊!轻轻松松搞定!

芒果酷2 2012-12-12 10:42:23
mysql> select distinct(a.MerchantNo) as "MerchantNo",a.LoginMobile as "LoginMobile",
a.Name as "Name",b.Address as "Address",c.SignTime as "st"
from T_M_MERCHANTS a
left join T_M_MERCHANTBUSIATTRIBUTES b on a.MerchantNo=b.MerchantNo
left join T_M_MERCHANTAGREEMENTS c on a.MerchantNo=c.MerchantNo
where a.Status=0 order by c.SignTime desc limit 2;
+-----------------+-------------+--------+------------------------------------+---------------------+
| MerchantNo | LoginMobile | Name | Address | st |
+-----------------+-------------+--------+------------------------------------+---------------------+
| 120910134113613 | 13337333210 | 金牛角 | 芙蓉区韶山北路139号湖南文化大厦1楼 | 2012-12-05 15:47:40 |
| 120910134113613 | 13337333210 | 金牛角 | 芙蓉区韶山北路139号湖南文化大厦1楼 | 2012-12-05 15:44:24 |
+-----------------+-------------+--------+------------------------------------+---------------------+
2 rows in set

mysql> select distinct(a.MerchantNo) as "MerchantNo",a.LoginMobile as "LoginMobile",
a.Name as "Name",b.Address as "Address"
from T_M_MERCHANTS a
left join T_M_MERCHANTBUSIATTRIBUTES b on a.MerchantNo=b.MerchantNo
left join T_M_MERCHANTAGREEMENTS c on a.MerchantNo=c.MerchantNo
where a.Status=0 order by c.SignTime desc limit 2;
+-----------------+---------------+------------+----------------------------------+
| MerchantNo | LoginMobile | Name | Address |
+-----------------+---------------+------------+----------------------------------+
| 1 | 0731-88888888 | 文化潇湘 | NULL |
| 120910142145401 | 0731-84171635 | 湖南大剧院 | 芙蓉区韶山北路139号文化大厦3-4楼 |
+-----------------+---------------+------------+----------------------------------+
2 rows in set

我这里少筛选一个字段c.SignTime as "st",怎么结果区别这么大,这个筛选本质是怎么样的啊,不明白了!另外我这里还做了去重啊,怎么没效果啊!还有跟下面这个的区别又在哪里啊!
mysql> select distinct(a.MerchantNo) as "MerchantNo",a.LoginMobile as "LoginMobile",
a.Name as "Name",b.Address as "Address"
from T_M_MERCHANTS a,T_M_MERCHANTBUSIATTRIBUTES b, T_M_MERCHANTAGREEMENTS c
where a.MerchantNo=b.MerchantNo and b.MerchantNo=c.MerchantNo
and a.Status=0 order by c.SignTime desc limit 2;
+-----------------+---------------+-----------------------+------------------------------------------+
| MerchantNo | LoginMobile | Name | Address |
+-----------------+---------------+-----------------------+------------------------------------------+
| 120910142145401 | 0731-84171635 | 湖南大剧院 | 芙蓉区韶山北路139号文化大厦3-4楼 |
| 120912100727412 | 0731-82827777 | 温莎KTV量贩(王府井店) | 芙蓉区黄兴中路27号王府井百货(近五一广场) |
+-----------------+---------------+-----------------------+------------------------------------------+
2 rows in set

mysql> select distinct(a.MerchantNo) as "MerchantNo",a.LoginMobile as "LoginMobile",
a.Name as "Name",b.Address as "Address",c.SignTime as "st"
from T_M_MERCHANTS a,T_M_MERCHANTBUSIATTRIBUTES b, T_M_MERCHANTAGREEMENTS c
where a.MerchantNo=b.MerchantNo and b.MerchantNo=c.MerchantNo
and a.Status=0 order by c.SignTime desc limit 2;
+-----------------+-------------+--------+------------------------------------+---------------------+
| MerchantNo | LoginMobile | Name | Address | st |
+-----------------+-------------+--------+------------------------------------+---------------------+
| 120910134113613 | 13337333210 | 金牛角 | 芙蓉区韶山北路139号湖南文化大厦1楼 | 2012-12-05 15:47:40 |
| 120910134113613 | 13337333210 | 金牛角 | 芙蓉区韶山北路139号湖南文化大厦1楼 | 2012-12-05 15:44:24 |
+-----------------+-------------+--------+------------------------------------+---------------------+
2 rows in set
他们的区别又在哪里啊!很晕了!求大侠!
...全文
85 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
liangchengfck1 2012-12-12
  • 打赏
  • 举报
回复
select distinct user_name,parameter from table select distinct user_name from table 是不一样的 usname parameter 张三 xx 张三 xxx 用这个sql会出现2条 select distinct user_name,parameter from table 如果没有parameter那只有一条 因为后面的参数parameter不一样 还有救是c.SignTime as st 这个是第三个table中的 所以有c.SignTime as st会去再检索第3个table 没有c.SignTime as st的数据据对<=有c.SignTime as st的sql语句 就好像group一样第一列检索万了会检索第二列

56,937

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧