Created
May 21, 2014 06:37
-
-
Save foxweb/a377873b493362b3c102 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mysql2' | |
client = Mysql2::Client.new(host: "127.0.0.1", username: "root", database: "test", encoding: "utf8") | |
File.open('9220.txt').each do |line| | |
line.chomp! | |
sql = "SELECT p.account, CONCAT(u.lname, ' ', u.fname, ' ', u.sname) username, u.email | |
FROM payments2 p JOIN users u ON userid = u.user_id | |
WHERE account = '#{line}'" | |
result = client.query(sql, symbolize_keys: true) | |
result.each do |row| | |
csv_line = "#{row[:account]};#{row[:username]};#{row[:email]}\n" | |
puts csv_line | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Так как там не требуется account, можно еще проще, одним запросом: