rechargedate | mobile | amount
-------------+----------------+--------
01-07-2009 | 0103001199 | 50.00
01-07-2009 | 0103001199 | 50.00
20-07-2009 | 0103001199 | 50.00
以上是我数据的一部分,现在我想在同一天将相同数量的充值变为一行:
rechargedate | mobile | Amount
--------------+---------------+--------
01-07-2009 | 0103001199 | 50.00
20-07-2009 | 0103001199 | 20.00
我该怎么做(转换?演员?)?
答案 0 :(得分:3)
SELECT DISTINCT columns FROM table GROUP BY columns
看起来你也需要GROUP BY
答案 1 :(得分:1)
SELECT DISTINCT columns FROM table WHERE .....
答案 2 :(得分:1)
也许您正在寻找distinct?
答案 3 :(得分:1)
如果两行相同,您可以在DISTINCT
之后使用SELECT
关键字:
select DISTINCT rechargedate, mobile, amount FROM yourTable
如果您有以下行:
,则无效rechargedate | mobile | amount
-------------+----------------+--------
01-07-2009 | 0103001199 | 150.00
01-07-2009 | 0103001199 | 50.00
20-07-2009 | 0103001199 | 50.00
在这种情况下,您需要GROUP BY
充值日期。这将为每个不同的充值日期仅获取一行,这可能并不总是您所需要的:
select rechargedate, mobile, amount FROM yourTable GROUP BY rechargedate
答案 4 :(得分:0)
SELECT rechargedate, mobile, SUM(amount) FROM tablename
GROUP BY rechargedate, mobile
答案 5 :(得分:0)
SELECT a.rechargedate, a.mobileno,sum(a.Amount),b.reg_dealer,
(c.agn_code + '-' + c.agn_master_code + '-' + c.agn_state + '-' + c.agn_dealer_code), b.reg_activationdate
from recharge a, dailyregistration b, agents c
where
substring(b.reg_dealer, 5, 6) = c.agn_dealer_code
and b.reg_id = a.mobileno
and month(a.rechargedate) = 7
group by a.rechargedate, a.mobileno, b.reg_dealer, (c.agn_code + '-' + c.agn_master_code + '-' + c.agn_state + '-' + c.agn_dealer_code), b.reg_activationdate
order by a.mobileno