If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > convert ms sql query to mysql

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-24-10, 12:09
mehrdad_t mehrdad_t is offline
Registered User
 
Join Date: Feb 2010
Posts: 2
Question convert ms sql query to mysql

hi

1 have a table with this structure and data
HTML Code:
ID	UserID	IP

----------------------------------

1	1	127.0.0.1
2	1	127.0.0.1
3	1	127.0.0.1
4	1	127.0.0.1
5	1	127.0.0.1
6	1	127.0.0.1
7	1	4.2.2.2
8	1	4.2.2.2
9	1	4.2.2.2
10	1	4.2.2.2
11	1	4.2.2.2
12	1	192.168.1.1
1 wrote this query in the Microsoft sql server :
Code:
select 

	distinct UserID ,IP ,
	
	ROUND(COUNT(IP)  / cast((select COUNT(userid) from Users) as float) , 2 ) as '%' 

	from Users
	
	group by UserID ,  ip ;

and results is :
HTML Code:
UserID      IP                   %
----------- -------------------- ----------------------
1           127.0.0.1            0.53
1           192.168.0.1          0.42
1           4.2.2.2              0.05

(3 row(s) affected)
i can`t convert it to mysql query

please help me
Reply With Quote
  #2 (permalink)  
Old 02-24-10, 13:43
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,084
Code:
SELECT UserID 
     , IP
     , ROUND( 1.00 * COUNT(IP) / 
         (SELECT COUNT(userid) FROM Users)  
            , 2 ) AS '%' 
	FROM Users
GROUP 
    BY UserID
     , IP
mysql does not support "cast as float" -- but then, you shouldn't need to do that in sql server, either

also, you don't need the DISTINCT in either mysql or sql server, because the groups produced by the GROUP BY clause are -- by definition -- distinct already
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-26-10, 03:41
mehrdad_t mehrdad_t is offline
Registered User
 
Join Date: Feb 2010
Posts: 2
thank u for ur attention
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On