dongqing6755 2011-01-27 02:29
浏览 29
已采纳

Mysql查询帮助 - 计算行数

I have two different tables trackingevent and link

Trackingevent looks like

eventName|eventStamp
SHARE_FACEBOOK|2011-01-20 14:05:40
SHARE_TWEET|2011-01-20 14:47:57
SHARE_FLICKR|2011-01-20 15:08:58
SHARE_STATION_LOGIN|2011-01-20 15:09:09
EMAIL_SHARE|2011-01-20 15:10:13
CONTEST_ENTRY:BLAH DATA|2011-01-20 15:10:13
CONTEST_ENTRY:BLAH DATA|2011-01-20 15:10:13

and link looks like

id|emailSub
6|1
7|0
8|1
9|0

And what I need to do is I need to count all the SHARE_FACEBOOK and all the SHARE_TWEET and all the SHARE_FLICKR and all the SHARE_STATION_LOGIN and all the COPNTEST_ENTRIES (Without the rest of the data after the :) AND EMAIL_SHARE and somehow combine those with the amount of emailSub (equals to 1) and amount of id.

So I get a returned array sort of like

EMAIL_SHARE     77
SHARE_FLICKR    9
SHARE_FACEBOOK  105
SHARE_STATION_LOGIN     223
SHARE_TWEET     18
# of ID's
# of emailsub=1
CONTEST_ENTERIES 550

I can get the first part of it using SELECT eventName, COUNT(*) FROM trackingevent GROUP BY eventName But I am confused with how to get the # of ID's in the link the # of emailsubs=1 and the number of CONTEST_ENTRY:BLAH DATA (the blah data changes).

Would I have to do three different sql queries and combine the data? Or could I somehow combine them into a single one or?

  • 写回答

1条回答 默认 最新

  • dongzan1970 2011-01-27 02:46
    关注

    This should give you the count of each type using the prefix

    SELECT LEFT(eventName,INSTR(CONCAT(eventName,':'),':')) as prefix, count(*)
    FROM trackingevent
    GROUP BY LEFT(eventName,INSTR(CONCAT(eventName,':'),':'))
    

    You'll have to answer the questions in the comments if this isn't what you were asking for

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程