duanliao5995 2013-05-13 04:42
浏览 10
已采纳

关于创建特定查询的疑问[关闭]

Ok I have a database where i generate a ticket code everytime a users buy an item. With this code they have the oportunity to win a price

To win the price they have to go to a register form, where the code is ask.. thats where the data is really generated. I ask for name, mail address, and other non important stuff

This part is working nice and properly. but i need to create o new function to detect the best buyers. So when they enter the code to participate , i ask for their mail, i have noticed, they actually enters the same mail each time they register a code. So this is the best way i think to select my best clients, and the most interested on promotions also.

So I think the best is to build a query to search into the mail row .. inside users table, and look for coincidences, and then this query can drop me a list of the most "repited" mails in DSC order,

is this posible, can i build a query like this? how?

Ok , thansk for the comments (why the downvote??) anyway

The structure is

ID | name | lastname | mail | phone | zipcode | birth |

And sorry at this moment i just CANT figure out a query thats why i ask. sorry for been a fool ,

  • 写回答

3条回答 默认 最新

  • dtr84664 2013-05-13 04:58
    关注

    How to order by the number of times a certain element occurs in a table

    SELECT COUNT(*) AS top,mail,name lastname FROM users GROUP BY mail ORDER BY top DESC

    This works because of aggregate functions

    COUNT

    Picks the number of rows in the individual elements of the group by (so suppose you ran count without a group by it would just return number of rows in the table)

    GROUP BY

    Groups the rows by common elements from the column(s) specified by the group by.

    So in the above case it will group all the mails together and count the rows in each group.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法