CREATE TABLE imgenusers ( TelegramId BIGINT(20) NOT NULL AUTOINCREMENT, Balance INT(11)…
- User
CREATE TABLE
imgen_users(TelegramIdBIGINT(20) NOT NULL AUTO_INCREMENT,BalanceINT(11) NOT NULL,Settings_ImageHeightINT(11) NOT NULL DEFAULT '0',Settings_ImageWidthINT(11) NOT NULL DEFAULT '0',Settings_StepsINT(11) NOT NULL DEFAULT '0',TotalDonatedINT(11) NOT NULL DEFAULT '0',TotalGeneratedINT(11) NOT NULL DEFAULT '0',LastBonusUseTimeBIGINT(20) NOT NULL DEFAULT '0',LimitedBalanceMaxINT(11) NOT NULL DEFAULT '10',LimitedBalanceUsedINT(11) NOT NULL DEFAULT '0',Settings_HrFixTINYINT(1) NOT NULL DEFAULT '0',JoinSourceINT(11) NOT NULL DEFAULT '0',JoinTimeBIGINT(20) NOT NULL DEFAULT '0',InvitedByBIGINT(20) NULL DEFAULT NULL,ReferralCountINT(11) NOT NULL DEFAULT '0',SelectedModelIdINT(11) NOT NULL DEFAULT '0',SubscriptionEndDateBIGINT(20) NOT NULL DEFAULT '0',SelectedPresetsLONGTEXT NOT NULL COLLATE 'utf8mb4_general_ci',ReferralBalanceINT(11) NOT NULL DEFAULT '0',TotalReferralBalanceINT(11) NOT NULL DEFAULT '0', PRIMARY KEY (TelegramId) USING BTREE ) COLLATE='utf8mb4_general_ci' ENGINE=InnoDB AUTO_INCREMENT=8107168691 ;make sql query to print user statics like users per 24 h, new users etc.
- Assistant
To create SQL queries for user statistics such as new users per 24 hours, the following queries can be useful:
1. Count New Users in the Last 24 Hours
This query calculates the number of new users who joined in the last 24 hours based on the
JoinTimefield.Assuming
JoinTimeis in Unix timestamp format, we can use the following SQL query:SELECT COUNT(*) AS new_users_last_24h FROM imgen_users WHERE JoinTime >= UNIX_TIMESTAMP(NOW() - INTERVAL 1 DAY);2. Total Number of Users
To get the total number of users:
SELECT COUNT(*) AS total_users FROM imgen_users;3. Count Users Who Were Active in the Last 24 Hours
If activity is defined by the
LastBonusUseTime, you could run:SELECT COUNT(*) AS active_users_last_24h FROM imgen_users WHERE LastBonusUseTime >= UNIX_TIMESTAMP(NOW() - INTERVAL 1 DAY); - User
make it in single
- Assistant
You can combine multiple statistics into a single query by using subqueries or by leveraging aggregate functions. Here's how you can gather various user statistics in a single query:
SELECT (SELECT COUNT(*) FROM imgen_users) AS total_users, (SELECT COUNT(*) FROM imgen_users WHERE JoinTime >= UNIX_TIMESTAMP(NOW() - INTERVAL 1 DAY)) AS new_users_last_24h, (SELECT COUNT(*) FROM imgen_users WHERE LastBonusUseTime >= UNIX_TIMESTAMP(NOW() - INTERVAL 1 DAY)) AS active_users_last_24h, (SELECT COUNT(*) FROM imgen_users WHERE TotalDonated > 0) AS users_donated, (SELECT COUNT(*) FROM imgen_users WHERE ReferralCount > 0) AS users_with_referrals;This single SQL statement will return a row with all the calculated statistics, which includes:
total_users: Total number of users in the database.new_users_last_24h: Number of users who joined in the last 24 hours.active_users_last_24h: Number of users who were active in the last 24 hours.users_donated: Number of users who have donated at least once.- : Number of users who have at least one referral.
- User
add activa user stats based on LastBonusUseTime
- Assistant
To include active user statistics based on the
LastBonusUseTimein the single query, you can extend the existing query structure with an additional subquery:SELECT (SELECT COUNT(*) FROM imgen_users) AS total_users, (SELECT COUNT(*) FROM imgen_users WHERE JoinTime >= UNIX_TIMESTAMP(NOW() - INTERVAL 1 DAY)) AS new_users_last_24h, (SELECT COUNT(*) FROM imgen_users WHERE LastBonusUseTime >= UNIX_TIMESTAMP(NOW() - INTERVAL 1 DAY)) AS active_users_last_24h, (SELECT COUNT(*) FROM imgen_users WHERE TotalDonated > 0) AS users_donated, (SELECT COUNT(*) FROM imgen_users WHERE ReferralCount > 0) AS users_with_referrals, (SELECT COUNT(*) FROM imgen_users WHERE LastBonusUseTime > 0) AS total_active_users_based_on_bonusThis query now includes:
total_active_users_based_on_bonus: The total number of users who have aLastBonusUseTimegreater than 0. This indicates users who have utilized a bonus feature at least once, potentially reflecting their engagement.
Each subquery retrieves a specific user statistic, and they are all combined in a single query to provide a comprehensive overview of user activity and engagement.