Mysql 如何生成不重复数据的两列

Mysql 如何生成不重复数据的两列,mysql,sql,Mysql,Sql,嗨,我能寻求一些帮助吗?我怎样才能生产这种lat,lng 我试过这个代码,但它不断重复lat,lng值 SELECT h.*, d.* from stdtbl h inner join ( select std_dtl_id,lat,lng, count(*) total from stdtbl_detail group by std_dtl_id ) d on h.id = d.std_dtl_id inner joi

嗨,我能寻求一些帮助吗?我怎样才能生产这种lat,lng

我试过这个代码,但它不断重复lat,lng值

SELECT h.*, d.* from
  stdtbl h 
  inner 
     join (
        select std_dtl_id,lat,lng, count(*) total 
       from stdtbl_detail group by std_dtl_id
     ) d

  on h.id = d.std_dtl_id
   inner join stdtbl_detail dt on h.id = dt.std_dtl_id
  where
  h.loginid = '1' AND  h.stdid='013777'
我怎样才能这样输出

id          stdid                 loginid                 std_dtl_id         lat                       lng                      total

372         013777                 1                      372                51.507407                 -0.127753                   4

372         013777                 1                      372                51.507384                 -0.127636                    4             

372         013777                 1                      372                51.507332                -0.127839                     4

372         013777                 1                      372                51.507304                 -0.127703                    4


373         013777                 1                      373               40.764442                  -73.923469                   4

373         013777                 1                      373               40.764416                   -73.923329                 4

373         013777                 1                      373               40.764346                   -73.923557                 4

373         013777                 1                      373                40.764299                   -73.923432                 4
这是演示


提前谢谢。

这应该满足您的要求:

  select h.*, d.*, f.total 
    from stdtbl h
      inner join stdtbl_detail d   
        on h.id = d.std_dtl_id
      inner join 
        (select std_dtl_id, count(*) total from stdtbl_detail group by std_dtl_id) f
          on f.std_dtl_id = h.id

我已经更新了你的小提琴:

这应该满足你的要求:

  select h.*, d.*, f.total 
    from stdtbl h
      inner join stdtbl_detail d   
        on h.id = d.std_dtl_id
      inner join 
        (select std_dtl_id, count(*) total from stdtbl_detail group by std_dtl_id) f
          on f.std_dtl_id = h.id

我已经更新了你的小提琴:

这应该满足你的要求:

  select h.*, d.*, f.total 
    from stdtbl h
      inner join stdtbl_detail d   
        on h.id = d.std_dtl_id
      inner join 
        (select std_dtl_id, count(*) total from stdtbl_detail group by std_dtl_id) f
          on f.std_dtl_id = h.id

我已经更新了你的小提琴:

这应该满足你的要求:

  select h.*, d.*, f.total 
    from stdtbl h
      inner join stdtbl_detail d   
        on h.id = d.std_dtl_id
      inner join 
        (select std_dtl_id, count(*) total from stdtbl_detail group by std_dtl_id) f
          on f.std_dtl_id = h.id

我已经更新了你的小提琴:

有了分析,这会很容易。如果没有,这仍然不是非常困难。首先,只需将两个表连接起来,即可获得所需的大部分输出

SELECT  s.id, s.stdid, s.loginid, d.lat, d.lng
from    stdtbl s
join    stdtbl_detail d
    on  d.std_dtl_id = s.id
where   s.loginid = '1'
    AND s.stdid   = '013777';
这将减少末尾的
total
字段,从而获得所需的内容。要实现这一点,只需为每个id生成一行结果,并连接到该结果:

SELECT  s.id, s.stdid, s.loginid, d.lat, d.lng, a.total
from    stdtbl s
join    stdtbl_detail d
    on  d.std_dtl_id = s.id
join(
    select  std_dtl_id, count(*) total 
    from    stdtbl_detail
    group by std_dtl_id
) a
    on  a.std_dtl_id = d.std_dtl_id
where   s.loginid = '1'
    AND s.stdid   = '013777';

有了分析,这将很容易。如果没有,这仍然不是非常困难。首先,只需将两个表连接起来,即可获得所需的大部分输出

SELECT  s.id, s.stdid, s.loginid, d.lat, d.lng
from    stdtbl s
join    stdtbl_detail d
    on  d.std_dtl_id = s.id
where   s.loginid = '1'
    AND s.stdid   = '013777';
这将减少末尾的
total
字段,从而获得所需的内容。要实现这一点,只需为每个id生成一行结果,并连接到该结果:

SELECT  s.id, s.stdid, s.loginid, d.lat, d.lng, a.total
from    stdtbl s
join    stdtbl_detail d
    on  d.std_dtl_id = s.id
join(
    select  std_dtl_id, count(*) total 
    from    stdtbl_detail
    group by std_dtl_id
) a
    on  a.std_dtl_id = d.std_dtl_id
where   s.loginid = '1'
    AND s.stdid   = '013777';

有了分析,这将很容易。如果没有,这仍然不是非常困难。首先,只需将两个表连接起来,即可获得所需的大部分输出

SELECT  s.id, s.stdid, s.loginid, d.lat, d.lng
from    stdtbl s
join    stdtbl_detail d
    on  d.std_dtl_id = s.id
where   s.loginid = '1'
    AND s.stdid   = '013777';
这将减少末尾的
total
字段,从而获得所需的内容。要实现这一点,只需为每个id生成一行结果,并连接到该结果:

SELECT  s.id, s.stdid, s.loginid, d.lat, d.lng, a.total
from    stdtbl s
join    stdtbl_detail d
    on  d.std_dtl_id = s.id
join(
    select  std_dtl_id, count(*) total 
    from    stdtbl_detail
    group by std_dtl_id
) a
    on  a.std_dtl_id = d.std_dtl_id
where   s.loginid = '1'
    AND s.stdid   = '013777';

有了分析,这将很容易。如果没有,这仍然不是非常困难。首先,只需将两个表连接起来,即可获得所需的大部分输出

SELECT  s.id, s.stdid, s.loginid, d.lat, d.lng
from    stdtbl s
join    stdtbl_detail d
    on  d.std_dtl_id = s.id
where   s.loginid = '1'
    AND s.stdid   = '013777';
这将减少末尾的
total
字段,从而获得所需的内容。要实现这一点,只需为每个id生成一行结果,并连接到该结果:

SELECT  s.id, s.stdid, s.loginid, d.lat, d.lng, a.total
from    stdtbl s
join    stdtbl_detail d
    on  d.std_dtl_id = s.id
join(
    select  std_dtl_id, count(*) total 
    from    stdtbl_detail
    group by std_dtl_id
) a
    on  a.std_dtl_id = d.std_dtl_id
where   s.loginid = '1'
    AND s.stdid   = '013777';


该输出也在重复值?请尝试使用
distinct
nevermind,不,它不会。您预期的输出是什么?您能解释一下吗@AmeyaDeshpande,我发布了我想要的输出,输出也在重复值?请尝试使用
distinct
nevermind,不,它没有。您期望的输出是什么?您能解释一下吗@AmeyaDeshpande,我发布了我想要的输出,输出也在重复值?请尝试使用
distinct
nevermind,不,它没有。您期望的输出是什么?您能解释一下吗@AmeyaDeshpande,我发布了我想要的输出,输出也在重复值?请尝试使用
distinct
nevermind,不,它没有。您期望的输出是什么?您能解释一下吗@AmeyaDeshpande,我发布了我想要的输出,
groupby
不是needed@pala_是的,我想这就是我想要的:)好吧,
groupby
不是needed@pala_是的,我想这就是我想要的:)好吧,
groupby
不是needed@pala_是的,我想这就是我想要的:)好吧,
groupby
不是needed@pala_是 啊我想这就是我想要的:)