Suppose I have a column with words:
orange
grape
orange
orange
apple
orange
grape
banana
How do I execute a query to get the top 10 words, as well as their count?
I currently have two tables:
1. car(plate_number, brand, cid)
2. borrow(StartDate, endDate, brand, id)
I want to write a query to get all available brand and count of available cars for each brand
Say we have a table
table posts
+---------+-----------+--------------------------------+
| postId | title | status | bodyText |
+---------+-----------+--------------------------------+
| 1 | Hello! | deleted | A deleted post! |
| 2 | Hello 2! | deleted | Another one! |
Can we, in SQL, retrieve a concatenation of a field across rows, by issuing a single query, not having to do the join up in a loop in our back-end code?
Something like
select title from posts group by status ;
Should give "Hello!, Hello 2!"
Hello all i have a problem that i just CANT get to work like i what it..
i want to show news and reviews (2 tables) and i want to have random output and not the same output
here is my query i really hope some one can explain me what i do wrong
SELECT
anmeldelser.billed_sti ,
anmeldelser.overskrift ,
anmeldelser.indhold ,
anmeldelser.id ,
anmeldelser.godkendt
FROM
anmeldelser
LIMIT 0,6
UNION ALL
SELECT
nyheder.id ,
nyheder.billed_sti ,
nyheder.overskrift ,
nyheder.indhold ,
nyheder.godkendt
FROM nyheder
ORDER BY rand() LIMIT 0,6
hi!
the query is:
select employee_id, last_name, salary, round((salary+(salary*0.15)), 0) as
NewSalary, (round((salary+(salary*0.15)), 0) - salary) as “IncreaseAmount”
from employees;
can i optimize this round((salary+(salary*0.15)), 0) part in anyway, so that it doesn't appear twice..i tried giving it an alias but didn't work :(
I have a sample Solr schema as follows
isPublic = boolean
source = facebook| twitter | wordpress
I want to write a query which returns all documents from the index which matches either the isPublic = true or isPublic is false and source= facebook. Something like this
solrUrl/?q=blah&fq=(isPublic:true OR (isPublic:false AND source:facebook))
Is such a thing possible or should I search the index two times with each of these conditions and then combine + de-duplicate the results?
i have stored in the database as
location
India,Tamilnadu,Chennai,Annanagar
while i bind in the grid view it ll be displaying as
'India,Tamilnadu,Chennai,Annanagar' this format.
but i need to be displayed as 'Annanagar,Chennai,Tamilnadu,India' in this format. how to perform this reverse order in query or in c#
iam having 2 tables
table Items Table (this table holds all items iam having)
itemId
---------
Item1
Item2
Item3
Item4
Item5
table 2 users_item relation
UserId || ItemId
1 || Item1
1 || Item2
userId one has stored 2 items Item1,Item2.
Now i want to write a query on table1 (Items table) so that it displays all items which user1 has NOT chosen.
i tried using this query:
"SELECT * FROM guests WHERE event_id=".$id." GROUP BY member_id;"
and I'm getting this error:
ERROR: column "guests.id" must appear in the GROUP BY clause or be used in an aggregate function
can anyone explain how i can work around this?
I'd like to get a better idea of what domains my customers are using. I could easily do this in PHP by explodeing each address and counting the domain that way. But I'm wondering if there's a way to get this information with just a plain MySQL query?
i have table country and having country name and country code,
i have customer table having countomer mobile number like customer_mobile field values like 0044-123456798 ,
0024-582654753 , 012-52686145 ,
i want to populate my country oce into combo,
that country name should in customer table which country code count is high that country name should come in the
dropdown list top ,
How to write the join query...
Thanks
i have interest rate and amount in a table where interest rate are ranged in different values
like 4.5,4.6,5.2,5.6 etc.
i want to get sum of amounts classified by interest rate where interest rate will be separated
by .25.
for example all amount having interest rate 1.25,1.3,1.4 will be in one group
and 1.5,1.67,1.9 will be in another group
how can i write the query?
I need to retrieve data from within a specific date range.Anybody can help me to create a query to getting the information within date range 12-12-2009 to 12-15-2009 from a mysql table.(including 12 and 15)
Here's the query:
INSERT INTO jobemails (jobid, to, subject, message, headers, datesent) VALUES ('340', '[email protected]', 'We\'ve received your request for a photo shoot called \'another\'.', 'message', 'headers', '2010-04-22 15:55:06')
The datatypes are all correct, it always fails at the subject, so it must be how I'm escaping the values, I assume.
I'm sure one of you will see my idiot mistake right away. A little help?
I need to write a query that creates a view that calculates the total cost of each sale, by considering quantity and price of each bought item. The view should return the debit and total cost.
In the answer each debit-number should only occur once.
Thanks in advance
Table ITEM:
ID NAME PRICE
118 Jeans 100
120 Towel 20
127 Shirt 55
Table DEBIT:
DEBIT ITEM Quantity
100581 118 5
100581 120 1
100586 127 5
I'm writing an InfoPath web form, using C# code behind. The form is a holiday request, after the user inputs the start and end dates I want the code to query a bank-holiday sharepoint list and count occurrences between the dates.
I've added the sharepoint list as a second datasource however I'm now stuck. Any ideas?
Hi all
Say I got 3 entities: Business, Employee and Payment. A payment has a foreign key to an Employee, while the Employee has an foreign key to a business.
Now, I want to create a query which gives me all payments for a given business. I really don't have a clue about how to do this - I guess I want something like:
mySession.CreateCriteria<Payment>()
.Add(Criterion.Expression.Eq(/* Employee_FK => Employee.Business_FK == BusinessID */);
Any help would be greatly appreciated :)
ID
NAME
AMT
1
Name1
1000
2
Name2
500
3
Name3
3000
4
Name1
5000
5
Name2
2000
6
Name1
3000
consider above table as sample.
am having a problem in my sql query, Am using like this.
Select name,amt from sample where amt between 1000 and 5000
it returns all the values in the table between 1000 and 5000, instead
I want to get maximum amount record for each name
i.e.,
3 name3 3000
4 name1 5000
5 name2 2000
So I have written a query that will grab an order (this is for an ecommerce type site), and from that order id it will get all order items (ecom_order_items), print options (c_print_options) and images (images). The eoi_p_id is currently a foreign key from the images table.
This works fine and the query is:
SELECT
eoi_parentid, eoi_p_id, eoi_po_id, eoi_quantity,
i_id, i_parentid,
po_name, po_price
FROM ecom_order_items, images, c_print_options WHERE eoi_parentid = '1' AND i_id = eoi_p_id AND po_id = eoi_po_id;
The above would grab all the stuff I need for order #1
Now to complicate things I added an extra table (ecom_products), which needs to act in a similar way to the images table. The eoi_p_id can also point at a foreign key in this table too. I have added an extra field 'eoi_type' which will either have the value 'image', or 'product'.
Now items in the order could be made up of a mix of items from images or ecom_products. Whatever I try it either ends up with too many records, wont actually output any with eoi_type = 'product', and just generally wont work. Any ideas on how to achieve what I am after? Can provide SQL samples if needed?
SELECT
eoi_id, eoi_parentid, eoi_p_id, eoi_po_id, eoi_po_id_2, eoi_quantity, eoi_type,
i_id, i_parentid,
po_name, po_price, po_id,
ep_id
FROM ecom_order_items, images, c_print_options, ecom_products WHERE eoi_parentid = '9' AND i_id = eoi_p_id AND po_id = eoi_po_id
The above outputs duplicate rows and doesnt work as expected. Am I going about this the wrong way? Should I have seperate foreign key fields for the eoi_p_id depending it its an image or a product?
Should I be using JOINs?
Here is a mysql explain of the tables in question
ecom_products
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| ep_id | int(8) | NO | PRI | NULL | auto_increment |
| ep_title | varchar(255) | NO | | NULL | |
| ep_link | text | NO | | NULL | |
| ep_desc | text | NO | | NULL | |
| ep_imgdrop | text | NO | | NULL | |
| ep_price | decimal(6,2) | NO | | NULL | |
| ep_category | varchar(255) | NO | | NULL | |
| ep_hide | tinyint(1) | NO | | 0 | |
| ep_featured | tinyint(1) | NO | | 0 | |
+-------------+--------------+------+-----+---------+----------------+
ecom_order_items
+--------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+----------------+
| eoi_id | int(8) | NO | PRI | NULL | auto_increment |
| eoi_parentid | int(8) | NO | | NULL | |
| eoi_type | varchar(32) | NO | | NULL | |
| eoi_p_id | int(8) | NO | | NULL | |
| eoi_po_id | int(8) | NO | | NULL | |
| eoi_quantity | int(4) | NO | | NULL | |
+--------------+-------------+------+-----+---------+----------------+
c_print_options
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| po_id | int(8) | NO | PRI | NULL | auto_increment |
| po_name | varchar(255) | NO | | NULL | |
| po_price | decimal(6,2) | NO | | NULL | |
+------------+--------------+------+-----+---------+----------------+
images
+--------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+----------------+
| i_id | int(8) | NO | PRI | NULL | auto_increment |
| i_filename | varchar(255) | NO | | NULL | |
| i_data | longtext | NO | | NULL | |
| i_parentid | int(8) | NO | | NULL | |
+--------------+--------------+------+-----+---------+----------------+
I have a column that contains links. The problem is that the titles of the links are in the same column, so it looks like this:
linktitle|-|linkurl
I want link title and linkurl in separate columns.
I've created a new column for the urls, so I'm looking for a way to extract them and update the linkurl column with them. Is there any clever way to construct a query that does this?
i need to get a query where the elements are displayed in case the first letter is E (the word is electronics).. i have tried with the following :
mysql_query("select * from nested_category where name like '[A-F]%'");
hi
i have this table:
id|date
1 | 10/11/2009
2 | 13/11/2009
1 | 20/12/2009
3 | 21/12/2009
1 | 30/12/2009
if i stand on the last record (id=1) and i need to see the last date where
id=1 is appear -- will show me: 1 | 20/12/2009
what query will do it ?
thank's in advance
hello, I am Running a oracle query, it seems to work except that it returns 4 dupes of each result.
here is the code:
Select * from (Select a.*, rownum rnum From (SELECT NEW_USER.*, NEW_EHS_QUIZ_COMPLETE.datetime FROM NEW_USER, NEW_EHS_QUIZ_COMPLETE WHERE EXISTS(select * from NEW_EHS_QUIZ_COMPLETE where NEW_USER.id=NEW_EHS_QUIZ_COMPLETE.USER_ID) ORDER by last_name ASC ) a where rownum <= #pgtop# ) where rnum >= #pgbot#
does anyone know why this isnt working properly? thanks in advance.
hi
i have 4000 records, and i need to pick randomize 500 records.
i need that 500 records will insert to GoodTable
and the rest 3500 records will insert to BadTable
how to do it using sql-server 2008 query ?
thank's in advance
Hi,
Is there a way to get the insert statements for a table via some query in MySql?
for ex: if the table name is Cards,which has 5 rows, i need to get the insert statements for that particular table.
Thanks.