在我的MySQL'购买'表一列存储user_name,因为每个完成的购买都存储在这里以及其他详细信息,例如shopping_cart_id,amount,我想获取user_name有超过10/50/100购买的内容。
我可以获得每个用户的购买记录数,但我想按行数过滤结果。这是我获取每个用户的记录数的查询。
$query = MySQL_query("SELECT user_name, COUNT(*) as count FROM purchase GROUP BY user_name ORDER BY count DESC") or die(MySQL_error());
感谢
答案 0 :(得分:1)
使用- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(100, 100);
}
子句
HAVING
(或)使用外部选择并过滤相同的
SELECT user_name,
COUNT(*) as count1
FROM purchase
GROUP BY user_name
HAVING COUNT(*) IN (100, 50, 10)
ORDER BY count1 DESC
答案 1 :(得分:0)
我在while循环中添加了一个if语句,它运行正常。我知道有更多方法可以实现这一结果。我的代码:
$query = MySQL_query("SELECT user_name, COUNT(*) as count FROM purchase GROUP BY user_name ORDER BY count DESC") or die(MySQL_error());
while($row = mysql_fetch_array($query))
{
$user_name = $row["user_name"];
$num_rows = $row['count'];
if($num_rows > '100'){
echo $user_name." – ".$num_rows."<br>";
}
}
此代码检索所有购买次数超过100的user_name,从高到低。