Hi Everyone,
I need help to write one query
Description:
I need to find out the every second Saturday of the each month of the year.
Thanks in advanced,
RPL
-schema
CREATE TABLE `ratings` (
`id` int(11) NOT NULL default '0',
`rating` int(11) NOT NULL default '1',
`rating_start` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
) TYPE=MyISAM
-myprogram.php
foreach($ids as $id){
$sql = "SELECT rating FROM ratings WHERE id = '$id' AND rating_start >= NOW()";
$sql .= "ORDER BY rating_start DESC LIMIT 1;"
$ret = $db->execute($id);
}
Can I teke same date from a Query?
by using id IN (".implode(",",$ids).") and GROUP BY id
I'm been trying to write a table trigger the queries another table that is outside the schema where the trigger will reside. Is this possible? It seems like I have no problem querying tables in my schema but I get:
Error: ORA-00942: table or view does not exist
when trying trying to query tables outside my schema. The documentation seems to elude to this notion, but it's not 100% clear to me.
In each table have many number of rows with amount. Like this i have different numbers of amount in each table. Each tables field name is different. How can i get the total of all values in the four tables in a single query? Any way is there?
I need to rewrite this query and I'm not allowed to use a subquery. I need to select the name and color of the parts that are heavier than the wheel.
SELECT name, color
FROM parts
WHERE weight > (SELECT weight FROM parts WHERE name="wheel");
This is the table:
PARTS
ID NAME COLOR WEIGHT
1 wheel black 100
2 tire black 50
3 gear red 20
Thanks in advance
What is the best SQL query to remove any text within parenthesis in a mySQL database? I'd like something that works regardless of the position of the parenthesis in the text (beginning, middle, end, whatever). I don't care about keeping the text inside the parenthesis, just removing it.
Thanks!
Hi,
I've a database that has a name field. (i.e Firstname M. Lastname or just Firstname Lastname).
Trying to filter by lastname.
How can I do a query to find the last space?
Something like
select * from person where name like "% a%" (but the space is the last space)
Thanks,
Tee
I can't figure out why I get a Object reference not set to an instance of an object. error if I use a ternary operator in my LINQ query.
var courses = from d in somesource
orderby d.SourceName, d.SourceType
select new
{
ID = d.InternalCode,
Name = string.Format("{0} - {1}{2}", d.InternalCode, d.SourceName, (d.SourceType.Length > 0 ? ", " + d.SourceType : string.Empty))
};
Any thoughts?
Here's the query i'm trying to convert into Linq:
SELECT R.Code,
R.FlightNumber,
S.[Date],
S.Station,
R.Liters,
SUM(R.Liters) OVER (PARTITION BY Year([Date]), Month([Date]), Day([Date])) AS Total_Liters
FROM S INNER JOIN
R ON S.ID = R.SID
WHERE (R.Code = 'AC')
AND FlightNumber = '124'
GROUP BY Station, Code, FlightNumber, [Date], Liter
ORDER BY R.FlightNumber, [Date]
Thanks for any help.
I have a scenario where I would want a plugin to construct a LINQ (to objects) query, send it across an appdomain and then apply and run it against a collection of my choosing
Is it possible, how?
If not, perhaps I could send a whole method (interface) across the appdomain and run it against the data on the appside? The main thing is that I want the data to reside in the CurrentDomain and the logic for operating on it in the plugin so I don't have to send the data across the boundary...
I have a problem with Hibernate Native Query. I have one SELECT that selects array slice (PostgreSQL database).
The problem is that hibernate recognizes the following part: ":300" from "SELECT my_array[1:300]..." as named parameter and I get the following exception: Not all named parameters have been set.
I tried to escape the colon (:) with '\:' , '::' but with no success.
The Hibernate version is 3.2
I have this mysql query:
SELECT *
FROM Customer c
JOIN eHRDemographic ehD ON ehD.CxID = c.CustomerID
JOIN CustPrimaryWeight cpW ON cpW.CxID = c.CustomerID
WHERE c.CustomerID =22703
GROUP BY c.CustomerID
ORDER BY cpW.CustPrimaryWeightID DESC
This doesn't really work correctly as the CustPrimaryWeight table has multiple enteries and it's simply joining the first entry and not the more recent one as the ORDER statement doesn't seem to do anything.
Any ideas?
Hello!
I'm running this query:
SELECT DISTINCT CONCAT(ALFA_CLAVE, FECHA_NACI) FROM listado GROUP BY ALFA_CLAVE HAVING count(CONCAT(ALFA_CLAVE, FECHA_NACI)) > 1
Is there any way to optimize it? Queries are taking 2-3 hours on a table with 850,000 rows.
Adding an index to ALFA_CLAVE and FECHA_NACI would work?
Thanks in advanced
i am trying to login and want to validate username and password against the records in the database. I am not sure how to pass two Where clause
public Boolean login(String username, String password) throws SQLException {
Cursor mCursor = db.query(TABLE_USERS, new String[] { ID,
KEY_NAME, KEY_USERNAME}, KEY_USERNAME + "="
+ "'"+username+"'", KEY_PASSWORD + "="
+ "'"+password+"'", null, null, null, null, null);
if (mCursor.moveToFirst()) {
return true;
}
return false;
}
Am getting a Syntax Error.
I know you can override delete and save methods in DJango models, but can you override a select query somehow to intercept and change a parameter slightly. I have a hashed value I want to check for, and would like to keep the hashing internal to the model.
i save a user like this in doctrine:
$user = User();
$user->name = 'peter';
$user->save();
is there a way to save 20 users in one sql query?
or do i have to loop the above code 20 times hence creating 20 sql queries?
thanks
Hi,
here is the "msg" table on mysql
sent_to customer msg read
------- -------- ------ -----
45 3 bla 0
34 4 bla 1
34 6 bla 0
45 3 bla 0
56 7 bla 1
45 8 bla 0
for example user whose id number is 45 logs in,
i want him to see this,
you have 2 unread msg to your "number 3" customer
you have 1 unread msg to your "number 8" customer
like a news feed
what query should i use for this ?
thx
Hi,
I have a table which have 6 million recods,when a fire select query with where condition in that table it is timing out.
How can I make it run, Please help
i have a table "request" with 4 columns namely:
1.recId :long primary key
2.interactionId:long
3.requestedBy:boolean
4.requestedType:boolean
and data is as follows:
VALUES
(185,455699,0,5),
(186,455746,0,1),
(187,455746,1,1),
(188,455752,0,1),
(189,455753,0,1),
(190,455753,1,1),
(191,455754,1,1)
i want a query to fetch all the rows where interactionId is same and having requestedBy both 1 and 0 values and requestType=1;
regards,
Nihar
Hi, I need to profile a large SQL query (in a particular database, not the whole server), and I cant figure out how to setup the profiler. I tried reading MSDN SQL web site, but it has not helped.
I am stuck at the Trace Properties "Events Selection" window. I need help as to which items to select in "Events Selection" window.
Thanks
Hi:
I need help to do this query select.
for example I have these fields:
idInvoice
date
amount
Depending of the date I need multiply the field "amount" for x number or other one.
For example, if the date is less 01/01/2010 to multiply for 20 . But if it is major or equal to multiply for 35
Select idInvoice, date, amount, amount * varNumber from invoices
I have a settingspropertyvaluecollection.I dont want to loop through all the properties using a for each loop.Instead i want to query the collection.How do i do that?is there a way to use LINQ and do it?
Thanks