李倩 发表于 2013-7-11 11:21:53

 SQL select 中group by的用法?

这是我的数据:num            voltage       others         date_time 0010852         1000         已打印         2013-4-260010852         3000         已打印         2013-4-26 0010853         2000         已打印         2013-4-260010853         1000         已打印         2013-4-260010854         2000         已打印         2013-4-250010854         6000         已打印         2013-4-250010855         2000         已打印         2013-4-25 0010855         3000         已打印         2013-4-250010855         3000         已打印         2013-4-25 我要的结果:0010854         8000         已打印         2013-4-250010855         8000         已打印         2013-4-25我的目的是让以num为地址的数据,只显示一条不重复数据,然后对voltage求和且只显示date_time是 "2013-4-25"的行。我用了以下公式:select num,sum(voltage) asvoltage,others,date_time from table where num is not null group bynum,others,date_time and date_time like "2013-4-25"group by 后面还能加上"anddate_time like "2013-4-25""好像跟没加效果一样的?实际结果:0010852         4000         已打印         2013-4-260010853         3000         已打印         2013-4-26 0010854         8000         已打印         2013-4-250010855         8000         已打印         2013-4-25

淡写轻描 发表于 2013-7-11 11:27:14

select num,sum(voltage) asvoltage,others,date_time from table where num is not nulland date_time =#2013-4-25# group by num,others,date_time
页: [1]
查看完整版本:  SQL select 中group by的用法?