I'm using SMS 2008 & I'm looking for where the registered servers are stores on my local machine. I have searched the registry with no luck.
AHIA,
Larry...
I have a column whose value is a json array. For example:
[{"att1": "1", "att2": "2"}, {"att1": "3", "att2": "4"}, {"att1": "5", "att2": "6"}]
What i would like is to provide a view where each element of the json array is transformed into a row and the attributes of each json object into columns. Keep in mind that the json array doesn't have a fixed size.
Any ideas on how i can achieve this ?
result=sqlstring.executeQuery("select distinct table_name,owner from all_tables ")
rs.append(str(i)+' , '+result.getString("table_name")+' , '+result.getString("owner"))
If i want to display the query select * from all_tables or ' select count(*) from all_tables'
how can i get the output to display . Please suggest thanks
Hi all,
I'm a lone developer for a telecoms company, and am after some database design advice from anyone with a bit of time to answer.
I am inserting into one table ~2 million rows each day, these tables then get archived and compressed on a monthly basis. Each monthly table contains ~15,000,000 rows. Although this is increasing month on month.
For every insert I do above I am combining the data from rows which belong together and creating another "correlated" table. This table is currently not being archived, as I need to make sure I never miss an update to the correlated table. (Hope that makes sense) Although in general this information should remain fairly static after a couple of days of processing.
All of the above is working perfectly. However my company now wishes to perform some stats against this data, and these tables are getting too large to provide the results in what would be deemed a reasonable time. Even with the appropriate indexes set.
So I guess after all the above my question is quite simple. Should I write a script which groups the data from my correlated table into smaller tables. Or should I store the queries result sets in something like memcache? I'm already using mysqls cache, but due to having limited control over how long the data is stored for, it's not working ideally.
The main advantages I can see of using something like memcache:
No blocking on my correlated table after the query has been cashed.
Greater flexibility of sharing the collected data between the backend collector
and front end processor. (i.e custom reports could be written in the
backend and the results of these stored in the cache under a key which
then gets shared with anyone who would want to see the data of this report)
Redundancy and scalability if we start sharing this data with a large amount of customers.
The main disadvantages I can see of using something like memcache:
Data is not persistent if machine is rebooted / cache is flushed.
The main advantages of using MySql
Persistent data.
Less code changes (although adding
something like memcache is trivial
anyway)
The main disadvantages of using MySql
Have to define table templates every time I want to store provide a new set of grouped data.
Have to write a program which loops through the correlated data and fills these new tables.
Potentially will still grow slower as the data continues to be filled.
Apologies for quite a long question. It's helped me to write down these thoughts here anyway, and any advice/help/experience with dealing with this sort of problem would be greatly appreciated.
Many thanks.
Alan
Hello,
Specifications: MySQL 4.1+
I've certain situation that requires certain result set from MySQL query, let's see the current query first & then ask my question:
SELECT thread.dateline AS tdateline, post.dateline AS pdateline, MIN(post.dateline)
FROM thread AS thread
LEFT JOIN post AS post ON(thread.threadid = post.threadid)
LEFT JOIN forum AS forum ON(thread.forumid = forum.forumid)
WHERE post.postid != thread.firstpostid
AND thread.open = 1
AND thread.visible = 1
AND thread.replycount >= 1
AND post.visible = 1
AND (forum.options & 1)
AND (forum.options & 2)
AND (forum.options & 4)
AND forum.forumid IN(1,2,3)
GROUP BY post.threadid
ORDER BY tdateline DESC, pdateline ASC
As you can see, mainly I need to select dateline of threads from 'thread' table, in addition to dateline of the second post of each thread, that's all under the conditions you see in the WHERE CLAUSE. Since each thread has many posts, and I need only one result per thread, I've used GROUP BY CLAUSE for that purpose.
This query will return only one post's dateline with it's related unique thread.
My questions are:
How to limit returned threads per
each forum!? Suppose I need only 5
threads -as a maximum- to be
returned for each forum declared in
the WHERE CLAUSE 'forum.forumid
IN(1,2,3)', how can this be
achieved.
Is there any recommendations for
optimizing this query (of course
after solving the first point)?
Notes:
I prefer not to use sub-queries, but if it's the only solution available I'll accept it. Double queries not recommended. I'm sure there's a smart solution for this situation.
Appreciated advice in advance :)
Hi,
I want to execute the following query using Subsonic:
SELECT MAX([restore_date]) FROM [msdb].[dbo].[restorehistory]
While the aggregate part is easy for me, the problem is with the name of the table. How should I force Subsonic to select from different database than default one.
what is the proper way of doing the following:
getting DATE as user input
running a query
generating a report that uses the query
this is the solution i was thinking:
have a form that takes user input
run the query
open the report
what is the correct way of doing this?
So I'm trying to take a search string (could be any number of words) and turn each value into a list to use in the following IN statement) in addition, I need a count of all these values to use with my having count filter
$search_array = explode(" ",$this->search_string);
$tag_count = count($search_array);
$db = Connect::connect();
$query = "select p.id
from photographs p
left join photograph_tags c
on p.id = c.photograph_id
and c.value IN ($search_array)
group by p.id
having count(c.value) >= $tag_count";
This currently returns no results, any ideas?
I think the best way to explain this is to tell you what I have.
I have two tables A and B both have columns Field1 and Field2. However Field 2 is not populated in table B
I want to populate field 2 of table B with field 2 of table A where field 1 of table A matches field 1 of table B.
something like update tableB set Field2 = tableA.field2 where tablea.field1 = tableb.field1.
The reason this may seem so odd and obscure is that I'm tyring to do an inital data load form an old database to a new one.
please let me know if you need clarification
I need to get the most recent record for each device from an upgrade request log table. A device is unique based on a combination of its hardware ID and its MAC address. I have been attempting to do this with GROUP BY but I am not convinced this is safe since it looks like it may be simply returning the "top record" (whatever SQLite or MySQL thinks that is).
I had hoped that this "top record" could be hinted at by way of ORDER BY but that does not seem to be having any impact as both of the following queries returns the same records for each device, just in opposite order:
SELECT extHwId,
mac,
created
FROM upgradeRequest
GROUP BY extHwId, mac
ORDER BY created DESC
SELECT extHwId,
mac,
created
FROM upgradeRequest
GROUP BY extHwId, mac
ORDER BY created ASC
Is there another way to accomplish this? I've seen several somewhat related posts that have all involved sub selects. If possible, I would like to do this without subselects as I would like to learn how to do this without that.
Hello,
I want to loop the update statement, but it only loops once.
Here is the code I am using:
do {
mysql_select_db($database_ll, $ll);
$query_query= "update table set ex='$71[1]' where field='val'";
$query = mysql_query($query_query, $ll) or die(mysql_error());
$row_domain_all = mysql_fetch_assoc($query);
} while ($row_query = mysql_fetch_assoc($query));
Thanks
Jean
Here are my tables
respondents:
field sample value
respondentid : 1
age : 2
gender : male
survey_questions:
id : 1
question : Q1
answer : sample answer
answers:
respondentid : 1
question : Q1
answer : 1 --id of survey question
I want to display all respondents who answered the certain survey, display all answers and total all the answer and group them according to the age bracket.
I tried using this query:
SELECT
res.Age,
res.Gender,
answer.id,
answer.respondentid,
SUM(CASE WHEN res.Gender='Male' THEN 1 else 0 END) AS males,
SUM(CASE WHEN res.Gender='Female' THEN 1 else 0 END) AS females,
CASE
WHEN res.Age < 1 THEN 'age1'
WHEN res.Age BETWEEN 1 AND 4 THEN 'age2'
WHEN res.Age BETWEEN 4 AND 9 THEN 'age3'
WHEN res.Age BETWEEN 10 AND 14 THEN 'age4'
WHEN res.Age BETWEEN 15 AND 19 THEN 'age5'
WHEN res.Age BETWEEN 20 AND 29 THEN 'age6'
WHEN res.Age BETWEEN 30 AND 39 THEN 'age7'
WHEN res.Age BETWEEN 40 AND 49 THEN 'age8'
ELSE 'age9'
END AS ageband
FROM Respondents AS res
INNER JOIN Answers as answer ON answer.respondentid=res.respondentid
INNER JOIN Questions as question ON answer.Answer=question.id
WHERE answer.Question='Q1' GROUP BY ageband ORDER BY res.Age ASC
I was able to get the data but the listing of all answers are not present. Do I have to subquery SELECT into my current SELECT statement to show the answers?
I want to produce something like this:
ex: # of Respondents is 3 ages: 2,3 and 6
Question: what are your favorite subjects?
Ages 1-4:
subject 1: 1
subject 2: 2
subject 3: 2
total respondents for ages 1-4 : 2
Ages 5-10:
subject 1: 1
subject 2: 1
subject 3: 0
total respondents for ages 5-10 : 1
I was trying to run the following query
UPDATE blog_post SET `thumbnail_present`=0, `thumbnail_size`=0, `thumbnail_data`=''
WHERE `blog_post` NOT IN (
SELECT `blog_post`
FROM blog_post
ORDER BY `blog_post` DESC
LIMIT 10)
But Mysql doesn't allow 'LIMIT' in an 'IN' subquery.
I think I can make a select to count the table rows and then make an ordered update limited by 'COUNT - 10', but I was wondering if there is a better way.
Thanks in advance.
im trying to work with the below code:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*; // important
import javax.mail.event.*; // important
import java.net.*;
import java.util.*;
public class servletmail extends HttpServlet
{
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException
{
PrintWriter out=response.getWriter();
response.setContentType("text/html");
try
{
Properties props=new Properties();
props.put("mail.smtp.host","localhost"); // 'localhost' for testing
Session session1 = Session.getDefaultInstance(props,null);
String s1 = request.getParameter("text1"); //sender (from)
String s2 = request.getParameter("text2");
String s3 = request.getParameter("text3");
String s4 = request.getParameter("area1");
Message message =new MimeMessage(session1);
message.setFrom(new InternetAddress(s1));
message.setRecipients
(Message.RecipientType.TO,InternetAddress.parse(s2,false));
message.setSubject(s3);
message.setText(s4);
Transport.send(message);
out.println("mail has been sent");
}
catch(Exception ex)
{
System.out.println("ERROR....."+ex);
}
}
}
im using mail.jar and activation.jar
but i cant understand how shouls i configure it with a mail server
which mail server should i use
will i be able to send an email using above
what are the requirements a mail server? how should i configure it
My table looks like this with duplicates in col1
col1, col2, col3, col4
1, 1, 0, a
1, 2, 1, a
1, 3, 1, a
2, 4, 1, b
3, 5, 0, c
I want to select distinct col1 with max (col3) and min(col2);
so result set will be:
col1, col2, col3, col4
1, 2, 1, a
2, 4, 1, b
3, 5, 0, c
I have a solution but looking for best ideas?
Suppose I have a table Recipe that hasmany ingredients.
I do a recursive find to grab recipes with their associated ingredients:
$this->Recipe->find('all', array('fields' => array('id','title','description')));
Here I can use the 'fields' attribute to specify that I only want it to return id, title, and description. However, despite this, cakephp still returns ALL columns from the ingredients table.
How do I tell cakephp that I only want ingredient table's id and name fields?
btw ingredient model is "Ingredient" and the table is ingredients, and the aggregation table is recipes_ingredients.
I have two tables, videos and videos_ratings. The videos table has an int videoid field (and many others but those fields are not important I think) and many records. The videos_ratings table has 3 int fields: videoid, rating, rated_by which has many records (multiple records for each fields from the videos table) but not for all records from the videos table.
Currently I have the following mysql query:
SELECT `videos`.*, avg(`videos_ratings`.`vote`)
FROM `videos`, `videos_ratings`
WHERE `videos_ratings`.`videoid` = `videos`.`videoid`
GROUP BY `videos_ratings`.`videoid`
ORDER BY RAND() LIMIT 0, 12
It selects all the records from table videos that have a rating in table video_ratings and calculates the average correctly. But what I need is to select all records from the videos table, no matter if there is a rating for that record or not. And if there aren't any records in the videos_ratings table for that particular videos record, the average function should show 0.
Hope someone could understand what I want... :)
Thanks!
today my problem is this i have 2 column and i wish check if the sum of that columns isn't Higher then a value(485 for example) and if is do a query...i though to do
SELECT * FROM table WHERE ColumnA+ColumnB<485
But isn't working... i've already tried with
SELECT Sum(ColumnA)+Sum(ColumnB) AS Total FROM table
but it gives me 1 column with the sum of all rows, i instead want a row for every sum. so how can i do..? xD i hope you understood if not just ask that i try to explain it better! and thanks in advice for who want to help me!
EDIT: I Found out XD the problem was that the columns was Smallint and the result of 1 or more rows was more than 32k so it wasn't working! Thanks At all!!
When you run something similar to:
UPDATE table SET datetime = NOW();
on a table with 1 000 000 000 records and the query takes 10 seconds to run, will all the rows have the exact same time (minutes and seconds) or will they have different times? In other words, will the time be when the query started or when each row is updated?
I'm running MySQL, but I'm thinking this applies to all dbs.
How to apply an update after an insert or update in POSTGRESQL; I have got a table which has a field lastupdate; I want that field to be set up whenever the row is updated or when it was inserted.
I tried this trigger, but It is not working! HELP!!
CREATE OR REPLACE FUNCTION fn_update_profile()
RETURNS TRIGGER AS $update_profile$
BEGIN
IF (TG_OP = 'INSERT' OR TG_OP = 'UPDATE' ) THEN
UPDATE profile SET lastupdate=now() where oid=OLD.oid;
RETURN NULL;
ELSEIF (TG_OP = 'DELETE') THEN
RETURN NULL;
END IF;
RETURN NULL; -- result is ignored since this is an AFTER trigger
END;
$update_profile$ LANGUAGE plpgsql;
i am trying to write a statment for counting the employees attendance and execute thier id , name and the days that he has working on the last 3 months by counting the duplicate id on NewTimeAttendance for month 1 , 2 and 3 ..
i tried to count :
Select COUNT(employeeid) from NewTimeAttendance where employeeid=1 and (month=1 or month =2 or month = 3)
This is absolutely working ,but just for one employee...
the secound try:
SELECT COUNT(NewEmployee.EmployeeID)
FROM NewEmployee INNER JOIN NewTimeAttendance
ON NewEmployee.EmployeeID = NewTimeAttendance.EmployeeID
and (month=1 or month =2 or month = 3)
This is working , but it counts all employees .. and i want it to execute each EmployeeId, EmployeeName and number of days as new record
last try: (before you see the code ... it is wrong ..but i am trying)
for i in 0..27 loop
SELECT COUNT(NewEmployee.EmployeeID),NewEmployee.EmployeeId,EmployeeName
FROM NewEmployee INNER JOIN NewTimeAttendance
ON NewEmployee.EmployeeID(i) = NewTimeAttendance.EmployeeID
and (month=1 or month =2 or month = 3)
end loop
i realy need help...thanks in advance
I'm importing a flat file of invoices into a database using C#. I'm using the TransactionScope to roll back the entire operation if a problem is encountered.
It is a tricky input file, in that one row does not necessary equal one record. It also includes linked records. An invoice would have a header line, line items, and then a total line. Some of the invoices will need to be skipped, but I may not know it needs to be skipped until I reach the total line.
One strategy is to store the header, line items, and total line in memory, and save everything once the total line is reached. I'm pursuing that now.
However, I was wondering if it could be done a different way. Creating a "nested" transaction around the invoice, inserting the header row, and line items, then updating the invoice when the total line is reached. This "nested" transaction would roll back if it is determined the invoice needs to be skipped, but the overall transaction would continue.
Is this possible, practical, and how would you set this up?
One day, wordpress suddenly jumped from pots id 9110 to 890000000 post.
Days later I'd like to move back new posts to continue from id 9111.
I'm sure that id will never reach id 890000000, no problem here, but id is an autoincrement field and "ALTER TABLE wp8_posts AUTO_INCREMENT =9111" is not working.
Can I force id to continue from 9111 ?