max

MYSQL last login and number of logins in last 3 months

*爱你&永不变心* 提交于 2020-01-11 06:32:11
问题 I'm trying to write a query to join a user table to an activity logging table and return the following for each user: A) The time they last logged in. B) The number of logins in the last 3 months. This is what I have come up with so far: SELECT A.UserID, COUNT( Activity ) AS Logins, MAX( TIME ) AS LastLogin FROM UserMaster A LEFT JOIN UserWebActivity B ON A.UserID = B.UserID AND Activity = 'Login' AND TIME BETWEEN DATE_SUB( NOW( ) , INTERVAL 3 MONTH ) AND NOW( ) GROUP BY A.UserID This almost

Ruby: How to find the key of the largest value in a hash?

杀马特。学长 韩版系。学妹 提交于 2020-01-10 02:18:46
问题 Hello I'm trying to find the largest value in my hash. I made a search in google and I found this code: def largest_hash_key(hash) key = hash.sort{|a,b| a[1] <=> b[1]}.last puts key end hash = { "n" => 100, "m" => 100, "y" => 300, "d" => 200, "a" => 0 } largest_hash_key(hash) in this code "puts" prints the largest key and value e.x y300. So, how I can modify the code in order to find the largest value and put it's key in to_s variable? 回答1: This is O(n): h = {"n" => 100, "m" => 100, "y" =>

Using Max() function to select group values

半城伤御伤魂 提交于 2020-01-09 12:05:08
问题 I've got a table like this: SKU ITEM VALUE 1503796 1851920 0,9770637 1503796 1636691 0,9747891 1503796 1503781 0,9741025 1503796 3205763 0,9741025 1503801 1999745 0,9776622 1503801 1999723 0,9718825 1503801 3651241 0,9348839 1503801 1773569 0,9331309 1503811 1439825 0,97053134 1503811 1636684 0,96297866 1503811 1636671 0,96003973 1503811 1600553 0,9535771 1503818 1636708 0,9440251 1503818 1636709 0,9440251 1503818 1779789 0,9423958 1503818 3322310 0,9369579 I need to get output like this

Using Max() function to select group values

余生长醉 提交于 2020-01-09 12:02:10
问题 I've got a table like this: SKU ITEM VALUE 1503796 1851920 0,9770637 1503796 1636691 0,9747891 1503796 1503781 0,9741025 1503796 3205763 0,9741025 1503801 1999745 0,9776622 1503801 1999723 0,9718825 1503801 3651241 0,9348839 1503801 1773569 0,9331309 1503811 1439825 0,97053134 1503811 1636684 0,96297866 1503811 1636671 0,96003973 1503811 1600553 0,9535771 1503818 1636708 0,9440251 1503818 1636709 0,9440251 1503818 1779789 0,9423958 1503818 3322310 0,9369579 I need to get output like this

how to select max of mixed string/int column?

只愿长相守 提交于 2020-01-09 10:11:04
问题 Lets say that I have a table which contains a column for invoice number, the data type is VARCHAR with mixed string/int values like: invoice_number ************** HKL1 HKL2 HKL3 ..... HKL12 HKL13 HKL14 HKL15 I tried to select max of it, but it returns with "HKL9", not the highest value "HKL15". SELECT MAX( invoice_number ) FROM `invoice_header` 回答1: HKL9 (string) is greater than HKL15 , because they are compared as strings. One way to deal with your problem is to define a column function that

how to select max of mixed string/int column?

强颜欢笑 提交于 2020-01-09 10:05:40
问题 Lets say that I have a table which contains a column for invoice number, the data type is VARCHAR with mixed string/int values like: invoice_number ************** HKL1 HKL2 HKL3 ..... HKL12 HKL13 HKL14 HKL15 I tried to select max of it, but it returns with "HKL9", not the highest value "HKL15". SELECT MAX( invoice_number ) FROM `invoice_header` 回答1: HKL9 (string) is greater than HKL15 , because they are compared as strings. One way to deal with your problem is to define a column function that

How to find the record in a table that contains the maximum value?

怎甘沉沦 提交于 2020-01-09 09:38:53
问题 Although this question looks simple, it is kind of tricky. I have a table with the following columns: table A: int ID float value datetime date varchar(50) group I would like to obtain the "ID" and "value" of the records that contain the maximum "date" grouped by the column "group". Something like "what is the newest value for each group?" I can get each group and its maximum date: SELECT group, MAX(date) FROM A GROUP BY group; -- I also need the "ID" and "value" But I would like to have the

How to find the record in a table that contains the maximum value?

自古美人都是妖i 提交于 2020-01-09 09:38:23
问题 Although this question looks simple, it is kind of tricky. I have a table with the following columns: table A: int ID float value datetime date varchar(50) group I would like to obtain the "ID" and "value" of the records that contain the maximum "date" grouped by the column "group". Something like "what is the newest value for each group?" I can get each group and its maximum date: SELECT group, MAX(date) FROM A GROUP BY group; -- I also need the "ID" and "value" But I would like to have the

How do I get the max and min values from a set of numbers entered?

不打扰是莪最后的温柔 提交于 2020-01-08 18:05:06
问题 Below is what I have so far: I don't know how to exclude 0 as a min number though. The assignment asks for 0 to be the exit number so I need to have the lowest number other than 0 appear in the min string. Any ideas? int min, max; Scanner s = new Scanner(System.in); System.out.print("Enter a Value: "); int val = s.nextInt(); min = max = val; while (val != 0) { System.out.print("Enter a Value: "); val = s.nextInt(); if (val < min) { min = val; } if (val > max) { max = val; } }; System.out

How do I get the max and min values from a set of numbers entered?

点点圈 提交于 2020-01-08 18:02:27
问题 Below is what I have so far: I don't know how to exclude 0 as a min number though. The assignment asks for 0 to be the exit number so I need to have the lowest number other than 0 appear in the min string. Any ideas? int min, max; Scanner s = new Scanner(System.in); System.out.print("Enter a Value: "); int val = s.nextInt(); min = max = val; while (val != 0) { System.out.print("Enter a Value: "); val = s.nextInt(); if (val < min) { min = val; } if (val > max) { max = val; } }; System.out