- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有几个表:
table user:
id firstname lastname
1 John Doe
2 Jane Skith
3 will Smith
...
table member:
member_id member_user_id member_status member_activated_by
10 1 yes partner 1
11 1 yes partner 2
12 1 yes partner 3
13 2 yes partner 2
14 3 no ----
...
table points:
points_id points_user_id points_value points_date
10 1 10 2012-02-15
11 2 15 2012-02-15
12 2 20 2012-02-15
13 1 5 2012-02-15
14 3 30 2012-02-15
15 1 12 2012-02-15
...
So results SHOULD be:
id1 - John Doe: 27 Points
id2 - Jane Skith: 35 Points
id3 - will Smith: nothing (not activated)
问题是,id1 带来了 81 点(因为他已经被激活了 3 次......)
这是我当前的 mysql 字符串(缩短...)
SELECT points_user_id, SUM( points_value ) AS points_total, id, firstname, lastname
FROM user
JOIN member ON member.member_user_id = user.id
JOIN points ON points.points_user_id = user.id
WHERE 1
AND member_status = 'yes'
GROUP BY points_user_id
ORDER BY points_total DESC
LIMIT 0 , 100
.. 到目前为止,它“几乎”按预期工作。
但是:用户可能有几个合作伙伴将他激活“进入激活”表。
现在调用它时,我得到了 points_total 的重复(它将被计算多次,因为 uesr 已被合作伙伴激活......)这在排名列表中没有多大意义......
如何为每个 user_id 获得“一个”points_total
希望你明白,我想要达到的目标......非常感谢!
最佳答案
我认为这应该可行,而不是加入激活进行子选择,您将在其中每个 user_id 只获得一行然后加入这个子选择,我不确定这是否是 MySql 语法,但它应该向您展示方法。唯一要注意的是,您在内部查询中选择的字段对于相同的 user_id 可能不会更改
SELECT user_id, SUM( point_row ) AS points_total, user_data...,...
FROM points
JOIN user_data AS UD
ON UD.user_id = points.user_id
JOIN ( SELECT field1,field2,field3, MAX(activation.user_id) as user_id
FROM activation WHERE activation_info = 'yes'
GROUP BY field1,field2,field3 AS ACTIV ) AS ACTIV
ON user_data.user_id = AS ACTIV.user_id
WHERE points.points_status = '1'
AND ACTIV.activation_info = 'yes'
GROUP BY points.user_id
ORDER BY total DESC
LIMIT 0 , 100
关于MySQL Statement (Group and SUM() => getting multiple "sum"result per line,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11615595/
我有点困惑为什么在 RoutineRetrieved 函数中分配 ACTIVITYIMAGE 时使用 result.getInt(2) 并在分配 SLOT 时使用 result.getInt(3)..
我是android领域的新手,我想从响应json数组访问每个结果元素,但我无法做到这一点,我试图获取每个元素,但我只得到一个值“rohit1”是第一个元素。请帮助我。 我是 rohit parmar,
我只有从 sql 查询返回的一行 (count(*)),但在执行包时,它向我显示上述错误,并且包失败。 我将结果类型设置为“单行”,并将查询的输出(select count(*) as 'result
我正在尝试使用Diesel将简单的原始SQL转换为MySQL,如本示例所示: https://docs.diesel.rs/diesel/fn.sql_query.html let users = s
我正在尝试 Play 框架的第一个示例,但出现了此错误 在我的路线文件中: # API # ~~~~ GET /api/geotweets/index controllers.api.GeoTw
这段代码可以返回null吗? (this.Result == Result.OK) 此行(或类似行)是否可以返回除 true 或 false 之外的任何内容(例如 null)? 最佳答案 (this.
我有一个 SSIS 执行 SQL 任务。它返回一个完整的结果集(即一个表)。但是,当我执行包时出现以下错误。我已经正确地为返回的结果集命名。 [执行 SQL 任务] 错误:对于完整的结果集和 XML
最近我刚刚将 swift 2.3 项目转换为 3.2,alamofire 也得到了转换,我收到了很多问题,其中大部分都已解决,现在我被给定的两个问题所困扰 问题在 alamofire 的 Respon
我在 R 中收到以下错误消息: Error in .verify.JDBC.result(r, "Unable to retrieve JDBC result set", : Unable to r
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 去年关闭。
我正在使用一个简单的命令运行以下存储过程sp_MSforeachdb。我的问题是如何限制结果仅显示至少有 1 条记录满足命令的数据库: 这是我的存储过程: EXECUTE master.sys.sp_
我在单独的线程中运行一些代码: fn f1() -> Result { Err("err1".to_string()) } fn f2() -> Result { Err("err2"
我在这里尝试使用 AsyncTask 从 OWM API 显示 7 天的天气预报。 doInBackground(String...param) 方法也工作正常。我检查了 LOGCAT。 异步完成执行
我已经创建了mysql的索引和全文索引,后端存储引擎是MyISAM。 mysql> show index from play_movie; +------------+------------+---
我有一个表articles,它的结构如下: id, name, date, contents 我有一个表authors,它的结构如下: id, article_id, name, email 一篇文章
我很困惑我们是否应该创建单独的 API 来获取结果和结果计数,或者我们应该只根据结果 API 中的查询字符串来获取计数。 /api/results/ : Fetches all records /ap
我正在制作一个将两个数字相除的系统,如果第二个数字不存在,它将选择第一个数字。这是代码: let new_num: f32 = match num1/num2 { Ok(num) => n
这个问题在这里已经有了答案: Why am I getting "unused Result which must be used ... Result may be an Err variant,
我正在修改 the texture synth 中的示例之一项目: use texture_synthesis as ts; fn main() -> Result { //create a
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: ^ operator in java 我假设 c ^ d是一个类似“的幂”的计算,所以c = 5 , d = 2 ,
我是一名优秀的程序员,十分优秀!