Dear Sir
Please help me
i want a query which out put is: - Vendor Amount
-
Computer
-
AA 52000
-
BB 20000
-
Total: 72000
-
Printer
-
XX 12000
-
YY 18000
-
Total: 30000
Thanks
3 2531
How your database look like?
Atli 5,058
Expert 4TB
Hey.
MySQL returns a two-dimensional list of data. What you posted is three-dimensional. You should generally avoid making MySQL jump through hoops to format the data in such a way, but rather leave that to your front-end code.
Having said that, check out the WITH ROLLUP modifier for the GROUP BY clause. It can give you a 2D representation of your 3D results. Not exactly what you posted, but close enough.
I used 3 tables for this query. Please help me - CREATE TABLE `item` (
-
`id` int(11) NOT NULL auto_increment,
-
`item_name` varchar(3) collate latin1_general_ci NOT NULL,
-
PRIMARY KEY (`id`)
-
)
-
-
INSERT INTO `item` VALUES (1, 'Computer');
-
INSERT INTO `item` VALUES (2, 'Printer');
- CREATE TABLE `vndr` (
-
`id` int(11) NOT NULL auto_increment,
-
`vndr_name` varchar(255) collate latin1_general_ci NOT NULL,
-
PRIMARY KEY (`id`)
-
)
-
-
INSERT INTO `vndr` VALUES (1, 'AA');
-
INSERT INTO `vndr` VALUES (2, 'BB');
-
INSERT INTO `vndr` VALUES (3, 'EE');
-
INSERT INTO `vndr` VALUES (4, RR');
-
INSERT INTO `vndr` VALUES (5, 'WW');
- CREATE TABLE `vt` (
-
`id` int(11) NOT NULL auto_increment,
-
`item_id` int(11) NOT NULL,
-
`vndr_id` int(11) NOT NULL,
-
`amount` double(10,2) NOT NULL,
-
`remarks` varchar(255) collate latin1_general_ci NOT NULL,
-
PRIMARY KEY (`id`)
-
)
-
-
INSERT INTO `vt` VALUES (1, 1, 1, 25000.00, '');
-
INSERT INTO `vt` VALUES (2, 1,1,25000.00, '');
-
INSERT INTO `vt` VALUES ( 3, 1, 2, 25000.00, '');
-
INSERT INTO `vt` VALUES (4, 2,4, 12000.00, '');
-
INSERT INTO `vt` VALUES (5, 2, 3, 18000.00, '');
-
INSERT INTO `vt` VALUES (6, 2, 3, 19000.00, '');
Thanks
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jerome |
last post by:
Hi,
I've got the following problem:
I want my ASP page to display a certain number (based on a COUNT query),
it works fine if the result is at least 1! If there are no records to be
counted...
|
by: Philip Stoev |
last post by:
Hi all,
Please tell me if any of this makes sense. Any pointers to relevant
projects/articles will be much appreciated.
Philip Stoev
http://www.stoev.org/pivot/manifest.htm
...
|
by: aj70000 |
last post by:
This is my query
select ano,max(date),a_subject from MY_TAB where table_name='xyz' and
ano=877
group by a_subject,ano order by a_subject
ANO max(Date) A_Subject
877 2005-01-20...
|
by: signaturefactory |
last post by:
I am trying the following query in and oleDbCommand:
SELECT PartLocations.LocationName, Sum(PartsJournal.Quantity) AS
SumOfQuantity, PartsJournal.PartsLotNumber
FROM PartLocations INNER JOIN...
|
by: m.k.ball |
last post by:
Thanks Rich - that's great. Before I found this group, I thought I had
a reasonable understanding of SQL (well, MySQL's implementation of it,
at least) but the truth is there are great chunks that...
|
by: Regnab |
last post by:
I often want to query the database with certain parameters in my query
which I do not want included in the query result.
The problem is when I want to group on 1, sum the 2nd (and group by)
and...
|
by: clare at snyder.on.ca |
last post by:
I have a SQL query I need to design to select name and email addresses
for policies that are due and not renewed in a given time period. The
problem is, the database keeps the information for every...
|
by: AJ |
last post by:
Folllowing on from a previous post, i have created a stored query as follows.
SELECT
c.ID, c.Company_Name, p., 1 As QueryNbr
FROM
(Company AS c LEFT JOIN Sale AS s ON c.ID = s.Company_ID)
LEFT...
|
by: Atli |
last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users.
Anyone should be able to get...
|
by: dsdevonsomer |
last post by:
Hello,
I have one simple query joining two tables with left outer join on 3
fields and using MIN on two fields. These two tables have lot of data
about 3 mil in total. I am trying to migrate db...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |